Dropzone.js以编程方式调用accept()函数
Dropzone.js invoke accept() function programmatically
我使用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();
}
}
});
现在看来,accept函数是在添加文件时调用的,而不是在从dropzone中删除文件时调用。那么,用程序调用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 ) {
这是一个不太理想的解决方案,但我发现,如果您以编程方式用现有文件模拟拖放功能,您可以实现类似的"重新处理现有文件"的结果。
这包括将文件存储到一个变量中,从Dropzone对象中删除文件,然后将文件添加回
// Single file example. For multiple use dropzone.addFiles(dropzone.files);
var singleFile = dropzone.files[0];
if (singleFile) {
dropzone.removeAllFiles(false);
dropzone.addFile(singleFile);
}
我在github上回答了这个问题:https://github.com/enyo/dropzone/issues/257
相关文章:
- 创建一个类似链接的按钮,并通过Javascript函数打开一个新的弹出窗口
- 将函数的上下文应用于javascript变量
- 如何在JavaScript中将字符串转换为函数引用
- 用嵌套函数和默认函数定义函数
- 使用 jQuery 的 .on 函数如何获取事件的原始元素
- 无法导出函数expressjs/requestjs中的变量
- 函数参数中的数据与指定变量之间的任何性能差异
- JQuery合并了keyup和focusout两个函数
- ES6构造函数返回基类的实例
- 监视函数从服务返回不起作用,但作用域函数起作用
- 我可以在json对象中添加一个函数吗
- AngularJS:我可以跳过函数参数回调吗
- 如何使jQuery插件函数可调用以供独立使用,而不在集合上操作
- JavaScript数组排序(函数)用于对表行进行排序,而不是排序
- jquery点击函数select&取消选择
- 拨打'父亲'函数形式a'儿童'ReactJS中的组件
- Node.js v6.2.0类扩展不是函数错误
- 比较从函数和生成的日期对象
- jQuery中是否内置了任何字符串格式化函数
- Dropzone.js以编程方式调用accept()函数