Javascript Dropzone.js 事件结束后上传前

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

Dropzone.js event after drop end and before uploading

javascripteventsdropzone.js

提问by ralvarez

I'm looking for a dropzone.jsevent that raises after the drop end and just before the uploading.

我正在寻找dropzone.js在下降结束之后和上传之前引发的事件。

What I need is to have access to all the information about the dropped files at once, not file by file thus addedfileevent is not an option.

我需要的是一次访问有关已删除文件的所有信息,而不是逐个文件,因此addedfile事件不是一个选项。

I thought that the dragendevent was the appropriate, but it's not triggered when I drop the files in my dropzone.

我认为该dragend事件是合适的,但是当我将文件放入我的放置区时它没有被触发。

The code snippet that I'm using looks like as follows:

我使用的代码片段如下所示:

Dropzone.options.myDropzone = {
    // Prevents Dropzone from uploading dropped files immediately
    autoProcessQueue : false,
    dictDefaultMessage: "Drop files or click here to upload a new DICOM series ...",
    init : function() {

        myDropzone = this;

        //Restore initial message when queue has been completed
        this.on("dragend", function(file) {
            console.log("ondragend");            
        });

    }

};

};

Am I missing something? Is there any other event in dropzone.jsfor this purpose?

我错过了什么吗?是否还有其他事件dropzone.js用于此目的?

回答by SimZal

There is an undocumented event called addedfiles, which will fire on both "drag-and-drop" and manual file selection.

有一个未记录的事件称为addedfiles,它将在“拖放”和手动文件选择时触发。

this.on("addedfiles", function(files) {
     console.log(files.length + ' files added');
});

回答by El Devoper

If you want to have a callback for the drop event, you should use 'drop'. In the event take a look at the 'files' Array. But be aware, that this event isn't fired if the user clicks at the dropzone and selects a file from there.

如果您想对 drop 事件进行回调,则应使用“drop”。在事件中查看“文件”数组。但请注意,如果用户单击放置区并从那里选择文件,则不会触发此事件。

Dropzone.options.MyDropzone = {
    autoProcessQueue : false,
    dictDefaultMessage: "Drop files or click here to upload a new DICOM series ...",
    init : function() {

        myDropzone = this;

        //Restore initial message when queue has been completed
        this.on("drop", function(event) {
            console.log(myDropzone.files);            
        });

    }
};

See this fiddle for example: jsfiddle.net/qqkbzv5a/2/

例如,请参阅此小提琴:jsfiddle.net/qqkbzv5a/2/

回答by ralvarez

Finally I have use the selectedfilesevent, which responses either the drop and the click action at the dropzone.

最后我使用了selectedfiles事件,它响应放置区的放置和点击操作。

 this.on("selectedfiles", function(listFiles) {
            cont_files = listFiles.length;
        });