Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

关于移除任务的疑问? #37

Open
kuyacai opened this issue Oct 11, 2023 · 0 comments
Open

关于移除任务的疑问? #37

kuyacai opened this issue Oct 11, 2023 · 0 comments

Comments

@kuyacai
Copy link

kuyacai commented Oct 11, 2023

先说一下我想实现的功能。在手动批量上传模式下(auto=false),要在客户端实现限制上传图片数的功能,假如是10个,当用户选择的文件超过或等于10个时,客户端隐藏“添加文件”按钮,如果客户此时点击预览图片上的“X”,也就是执行了“移除”操作,那么此时待上传的图片数是少于10个的,这时候应该允许用户再添加图片。这里的用户操作场景可以理解为:用户预览图片后,发现某张或某几张图片不满意,需要重新选择。
我在调试时发现,用户执行“移除”操作后,并没有从任务列表(Uploader.list)中移除该任务,只是添加了删除标志:task.deleted = true; 而在remove方法中,看到如下注释:

//移除任务
        remove: function (taskId) {
            var task = this.get(taskId);
            if (!task) return;

            if (task.state == UPLOAD_STATE_PROCESSING) this.cancel(taskId);

            //this.list.splice(task.index, 1);
            //this.map[task.id] = undefined;

            //从数组中移除任务时,由于任务是根据index获取,若不处理index,将导致上传错乱甚至不能上传
            //此处重置上传索引,上传时会自动修正为正确的索引(程序会跳过已处理过的任务)
            //this.index = 0;

            //添加移除标记(用户可以自行操作,更灵活)
            task.deleted = true;

            this.fire("remove", task);
        },

从任务列表中移除任务的代码被注释掉了。
我的疑问是:是什么原因需要注释掉该代码?如果启用该代码,会带来哪些影响?多谢!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant