2017-06-14 305 views
0

我有我的懸浮窗的問題,Dropzone.js - 刪除預覽文件,如果上傳失敗

$(".js-example-basic-multiple").select2(); 
Dropzone.options.dropZone = { 
    //options here 
    maxFilesize: 2, 
    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(); 
    }, 
    init: function() { 
     this.on("maxfilesexceeded", function(file){ 
      alert("No more files please!"); 
     }); 
    } 
} 

我的問題是,當一個文件未能上載,它仍然顯示預覽圖像,所以我需要的是當這些文件上傳失敗時會自動刪除文件,我該怎麼做?

+0

Tq for smarx,抱歉我的英文不好 – Wolfzmus

回答

1

我想,如果我理解正確的話,你可以使用此代碼刪除圖像:

Dropzone.options.dropZone = { 
    ... 
    , error: function(file, message, xhr) { 
     $(file.previewElement).remove(); 
    }, 
    ... 
} 

只需再次閱讀文檔。 此代碼是從文檔:

myDropzone.on("error", function(file) { 
    myDropzone.removeFile(file); 
}); 

請讓我知道,如果它在你的情況。

+0

好吧我要去嘗試ttaht。 – Wolfzmus

+0

更新:工作! Tq非常幫你 – Wolfzmus