【问题标题】:Dropzone max file only one and remove the second fileDropzone max 文件只有一个并删除第二个文件
【发布时间】:2018-02-24 03:08:27
【问题描述】:

我只是这样使用我的代码

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();
            }
        };

当我上传第二个文件时显示警报“请不要再有文件!”,没有上传的文件工作正常,但我的问题是,我添加的第二个文件仍然显示在我的 dropzone 上。我的问题是如何在显示警报后自动删除第二个文件??

【问题讨论】:

    标签: dropzone


    【解决方案1】:

    如果你想删除最大文件扩展文件,你只需要使用 dropzone 的maxfilesexceeded 方法

        init: function() {
             myDropzone.on("maxfilesexceeded", function (file) {
                    this.removeFile(file);
                });
        },
    

    或者你也可以使用其他方法

      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);
                    }
    
                });
     },
    

    【讨论】:

    • 第一个解决方案更好。 Tq :)
    【解决方案2】:

    我终于解决了我的问题。 在

     init: function() {
                this.on("maxfilesexceeded", function(file){
                    alert("No more files please!");
                });
            },
    

    我改成这样

    init: function() {
                this.on("maxfilesexceeded", function(file){
                    alert("No more files please!");
                    this.removeFile(file);
                });
            },
    

    是我想要的完美工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-03-27
      • 2020-06-12
      • 1970-01-01
      • 1970-01-01
      • 2014-05-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多