Javascript 获取 dropzone 中选定文件的数量

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29910240/
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-08-23 04:17:49  来源:igfitidea点击:

Get count of selected files in dropzone

javascriptarraysdropzone.js

提问by Dumidu Madushanka

What I m trying to do is get a count of selected files in dropzone before upload them.

我想要做的是在上传之前获取 dropzone 中选定文件的数量。

var count= myDropzoneNST.getAcceptedFiles().length;

I can get a count of uploaded files using this line, but What I m trying to do is to get count of selected valid files before upload them.

我可以使用这一行获取上传文件的数量,但我想要做的是在上传之前获取所选有效文件的数量。

回答by IamNaN

var count= myDropzoneNST.files.length;

will give you the total number of files in your dropzone.

将为您提供 dropzone 中的文件总数。

回答by Camille

// To access all files count
myDropzone.files.length
// To access only accepted files count
myDropzone.getAcceptedFiles().length
// To access all rejected files count
myDropzone.getRejectedFiles().length
// To access all queued files count
myDropzone.getQueuedFiles().length
// To access all uploading files count
myDropzone.getUploadingFiles().length

Get from document API here

此处获取文档 API

回答by joho

My experience is that the .get*Files()methods are not very accurate. The .getAcceptedFiles().lengthusage will return the current number of accepted files minus the one just having been added, if you call it from the addedFile()event handler, for example. This may be "as designed", but it makes the wording of "addedFile()" somewhat odd.

我的经验是这些.get*Files()方法不是很准确。例如.getAcceptedFiles().length,如果您从addedFile()事件处理程序调用它,则用法将返回当前已接受文件数减去刚刚添加的文件数。这可能是“按设计”,但它使“ addedFile()”的措辞有些奇怪。