fex-team / webuploader

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

removeFile(fid)后getFiles()发现文件仍然存在于列表 #1288

Open ccwq opened 9 years ago

ccwq commented 9 years ago

removeFile(fid)后getFiles()发现文件仍然存在于列表。结果就是我选择了4个文件,removeFild 了1个,getFiles得到的结果仍然是4个。api我没看仔细还是,我打开方式不对。

jamky commented 8 years ago

嗯,我也是这个问题,因为webuploader居然不支持只能单张传图的模式,所以这样去修改 uploader.on('beforeFileQueued', function (file) { if (this.getFiles() > 0) this.removeFile(this.getFiles()[0], true); }), 使其只支持单张模式,结果遇到你说的这个Bug, 删除根本不起作用,通过getFiles()再次检测发现文件仍然存在于列表,坑人呀

wglgithub commented 8 years ago

同楼上

a-la-shen-ding commented 8 years ago

需要根据file的id在percentages里再删除一次:delete percentages[ file.id ];

kevin123de commented 8 years ago

请问percentages在哪里定义的啊 ?

yaowangmx commented 8 years ago

多文件上传里面调用这个的话,delete percentages[ file.id ];会报错 @a-la-shen-ding

a-la-shen-ding commented 8 years ago

@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是确实正确,你可以输出一下它,看正不正确。

a-la-shen-ding commented 8 years ago

@kevin123de percentages自己定义的 所有文件的进度信息,key为file id,初始化为{},在添加文件的时候赋值percentages[file.id] = [file.size, 0];