fex-team / webuploader

It's a new file uploader solution!
http://fex.baidu.com/webuploader/
BSD 3-Clause "New" or "Revised" License
7.71k stars 2.33k forks source link

Uncaught ReferenceError: $list is not defined #2609

Open mingzhongshui opened 7 years ago

mingzhongshui commented 7 years ago

`// 当有文件添加进来的时候 uploader.on( 'fileQueued', function( file ) { var $li = $( '

' + '' + '
' + file.name + '
' + '
' ), $img = $li.find('img');

// $list为容器jQuery实例
$list.append( $li );

// 创建缩略图
// 如果为非图片文件,可以不用调用此方法。
// thumbnailWidth x thumbnailHeight 为 100 x 100
uploader.makeThumb( file, function( error, src ) {
    if ( error ) {
        $img.replaceWith('<span>不能预览</span>');
        return;
    }

    $img.attr( 'src', src );
}, thumbnailWidth, thumbnailHeight );

});`

Uncaught ReferenceError: $list is not defined

mingzhongshui commented 7 years ago

自己找到问题了: $list为上传图片列表的容器; 自己定义一个<div id='ptlist'></div> 然后在把$list = $('#ptlist') 在script最开始的地方把$定义好 var $ = jQuery; 改完这些后还会报错: thumbnailWidth not define 在定义一下这两个参数 ratio = window.devicePixelRatio || 1, // 缩略图大小 thumbnailWidth = 110 * ratio, thumbnailHeight = 110 * ratio, 以上就可以解决了。 PS:吐槽:demo给的不全,是让开发者踩坑吗?demo发布出去之前自己不测试的吗?真是服了,就折腾这么个问题浪费我一上午时间

lancecm commented 5 years ago

时隔两年,非常感谢~

mingzhongshui commented 5 years ago

能对你有帮助就好~