我使用Dropzone.js,併爲拒絕具有相同文件名的文件的文件實現了自定義約束。我的繼承人初始化代碼:Dropzone.js以編程方式調用accept()函數
var myDropzone = new Dropzone("div#myId", {
url: MpgCommon.app.route('upload_files_path'),
addRemoveLinks: true,
thumbnailWidth: "80",
thumbnailHeight: "80",
dictCancelUpload: "Cancel",
parallelUploads: 12,
uploadMultiple: false,
autoProcessQueue: false,
accept: function(file, done) {
var selected_filenames = $.map(myDropzone.files, function(selected_file) {
return (selected_file.name.replace(/\.[^.]+$/, ''));
});
var filename = file.name.replace(/\.[^.]+$/, '')
if ($.inArray(filename, selected_filenames) != selected_filenames.length-1){
var error_msg = "Error!";
$('.edit_tooltip .gui_message.error').css({display: "block"}).html(error_msg);
done(error_msg);
}
else {
$('.edit_tooltip .gui_message.error').css({display: "none"}).html('');
done();
}
}
});
現在看來,當添加的文件被接受函數被調用而不是當一個文件從懸浮窗中刪除。那麼是否可以通過編程來調用accept函數?
我嘗試這樣做,但它不到風度工作:
myDropzone.on("removedfile", function(file) {
var rejected_files = myDropzone.getRejectedFiles();
console.log(rejected_files);
rejected_files.forEach(function() {
console.log(this);
myDropzone.accept(this);
});
});
我在控制檯得到的錯誤是:
TypeError: done is not a function
if (args) {