Dropzone 最大文件只有一个并删除第二个文件

Wol*_*mus 5 dropzone

我只是像这样使用我的代码

Dropzone.options.attachkyc = {
            maxFiles: 1,
            accept: function(file, done) {
            console.log("uploaded");
            done();
            },
            init: function() {
                this.on("maxfilesexceeded", function(file){
                    alert("No more files please!");
                });
            },
            addRemoveLinks: true,
            removedfile: function(file) {
                var name = file.name;        
                $.ajax({
                    type: 'POST',
                    url: host+'upload/unfile',
                    data: "id="+name,
                    dataType: 'html'
                });
                var _ref;
                return (_ref = file.previewElement) != null ? _ref.parentNode.removeChild(file.previewElement) : void 0;   

                //console.log();
            }
        };
Run Code Online (Sandbox Code Playgroud)

当我上传第二个文件时,显示警报“请不再有文件!”,文件未上传的情况良好,但我的问题是,我添加的第二个文件仍然显示在我的拖放区中。我的问题是在显示警报后如何自动删除第二个文件?

小智 5

如果你想删除 max file 扩展文件,你只需要使用maxfilesexceededdropzone 的方法

    init: function() {
         myDropzone.on("maxfilesexceeded", function (file) {
                this.removeFile(file);
            });
    },
Run Code Online (Sandbox Code Playgroud)

或者你也可以使用另一种方法

  init: function() {
  myDropzone.on("addedfile", function (file) {

                if (myDropzone.files.length === 1) {
                    alert("You can Select upto 1 Pictures for Venue Profile.", "error");
                    this.removeFile(file);
                }

            });
 },
Run Code Online (Sandbox Code Playgroud)