简体   繁体   English

单个页面中的多个 Dropzone

[英]Multiple Dropzone in a single page

I'm using Dropzone without creating a dropzone form.我正在使用 Dropzone 而不创建 dropzone 表单。 It works great for me in this way.它以这种方式对我很有用。

But in this case I can not create another instance of Dropzone in my page.但在这种情况下,我无法在我的页面中创建另一个 Dropzone 实例。

var myDropzone1 = new Dropzone(
        document.body,
        {
            url : "upload1"...
            .
            .
            . some parameters
         };

var myDropzone2 = new Dropzone(
        document.body,
        {
            url : "upload'"...
            .
            .
            . some parameters
         };

When I do this, I'm getting the error Dropzone already attached.当我这样做时,我收到错误Dropzone already attached.

It's possible, but you can't bind a second dropdzone on the same element, as you did.这是可能的,但是您不能像以前那样在同一元素上绑定第二个 dropdzone。 2 Dropzones on one element makes no sense. 2 Dropzones 在一个元素上是没有意义的。 2x document.body in your solution atm.解决方案 atm 中的 2x document.body。 Try this...尝试这个...

HTML: HTML:

<form action="/file-upload" class="dropzone" id="a-form-element"></form>
<form action="/file-upload" class="dropzone" id="an-other-form-element"></form>

JavaScript: JavaScript:

var myDropzoneTheFirst = new Dropzone(
        //id of drop zone element 1
        '#a-form-element', { 
            url : "uploadUrl/1"
        }
    );

var myDropzoneTheSecond = new Dropzone(
        //id of drop zone element 2
        '#an-other-form-element', { 
            url : "uploadUrl/2"
        }
    );

I want to add something here because I have experienced problems with multiple dropzones on the same page.我想在这里添加一些东西,因为我在同一页面上遇到了多个放置区的问题。

In your init code you must remember to include var if putting a reference otherwise it isn't dealing with this instance of the dropzone rather trying to access/relate to the others.在您的 init 代码中,您必须记住在放置引用时包含 var,否则它不会处理 dropzone 的这个实例,而是试图访问/关联到其他实例。

Simple javascript but makes a big difference.简单的javascript,但有很大的不同。

init:       function(){
    var dzClosure = this;

    $('#Btn').on('click',function(e) {
        dzClosure.processQueue();
    });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM