我使用Dropzone.js并为拒绝具有相同文件名的文件的文件实现了自定义约束。这是我的初始化代码:
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();
}
}
});
现在似乎在添加文件时调用了接受函数,而不是在从 dropzone 中删除文件时调用。那么是否可以通过编程方式调用接受函数?
我试过这个,但它不起作用:
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 ) {