Open ccwq opened 9 years ago
嗯,我也是这个问题,因为webuploader居然不支持只能单张传图的模式,所以这样去修改 uploader.on('beforeFileQueued', function (file) { if (this.getFiles() > 0) this.removeFile(this.getFiles()[0], true); }), 使其只支持单张模式,结果遇到你说的这个Bug, 删除根本不起作用,通过getFiles()再次检测发现文件仍然存在于列表,坑人呀
同楼上
需要根据file的id在percentages里再删除一次:delete percentages[ file.id ];
请问percentages在哪里定义的啊 ?
多文件上传里面调用这个的话,delete percentages[ file.id ];会报错 @a-la-shen-ding
@yaowangmx 不清楚你那边具体状况,下面这个是我reset uploader的时候的代码 ` var oldFiles = uploader.getFiles(); //获取所有的文件
var fileLength = oldFiles.length;
for (var i = 0; i < fileLength; i++) { //对文件逐一操作
var fileid = oldFiles[i].id;
var $li = $('#' + fileid);
uploader.removeFile(oldFiles[i], true); //删除文件
delete percentages[fileid]; //根据id删除percentages中的文件
updateTotalProgress();
$li.remove();
}
uploader.reset();`
这个是removefile的方法 `// 负责view的销毁
function removeFile(file) {
var $li = $('#' + file.id);
delete percentages[file.id];
updateTotalProgress();
$li.off().find('.file-panel').off();
$li.remove();
}`
首先要确保你的file.id中的 file是确实正确,你可以输出一下它,看正不正确。
@kevin123de percentages自己定义的 所有文件的进度信息,key为file id,初始化为{},在添加文件的时候赋值percentages[file.id] = [file.size, 0];
removeFile(fid)后getFiles()发现文件仍然存在于列表。结果就是我选择了4个文件,removeFild 了1个,getFiles得到的结果仍然是4个。api我没看仔细还是,我打开方式不对。