2017-09-15 41 views
0

我只是用我的代码,这样悬浮窗MAX文件只有一个,并删除第二个文件

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

当我上传第二个文件是显示警告“没有更多的文件,请!”,以及正在taht文件没有上传,但我的问题是,我添加它的第二个文件仍然显示在我的dropzone上。我的问题是我如何自动删除第二个文件后,我显示警报?

回答

1

,如果你想删除最大文件扩展的文件,你只需要使用悬浮窗

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

maxfilesexceeded方法,或者你也可以用另外一种方式太

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

      }); 
}, 
+0

第一个解决方案是更好的。 Tq :) – Wolfzmus

0

我最终解决了我的问题。 上在

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

是完美的工作,我想。

相关问题