javascript 从 Dropzone.js 中删除所有手动添加的文件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21875073/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 21:53:43  来源:igfitidea点击:

removing all manually added files from Dropzone.js?

javascriptdropzone.js

提问by AMIB

There is a unknown problem while programmatically deleting programmatically added files to Dropzone. Here is my code that is not working:

以编程方式删除以编程方式添加到 Dropzone 的文件时出现未知问题。这是我的代码不起作用:

// constructor - OK
docsDropzone = new Dropzone( "#docsUpload", {
    url: uploadUrl,
    addRemoveLinks: true,
    init: function() {
        this.on( 'removedfile', removedFileCallback );
    }
} );

// add file - OK
var mockFile = { name: 'test.jpg', size: 0 };
docsDropzone.emit( "addedfile", mockFile );
docsDropzone.emit( "thumbnail", mockFile, 'test.jpg' );

// remove files - NOT OK
docsDropzone.removeAllFiles( true );

回答by AMIB

addedfilefunction is not adding files to dropzone.filesso it must be added manually:

addedfile函数不会向其中添加文件,dropzone.files因此必须手动添加:

// add file - OK
var mockFile = { name: 'test.jpg', size: 0, status: 'success' };
docsDropzone.emit( "addedfile", mockFile );
docsDropzone.emit( "thumbnail", mockFile, 'test.jpg' );
docsDropzone.files.push( mockFile ); // file must be added manually

// remove files - NOW OK
docsDropzone.removeAllFiles( true );