【问题标题】:Check if Dropzone is already attached检查 Dropzone 是否已附加
【发布时间】:2016-11-01 12:09:19
【问题描述】:

页面上的 dropzone 很少,并且新项目由 ajax 加载,所以 我需要检查 dropzone 是否已附加到该项目上

    Dropzone.autoDiscover = false;


    function initDropzones()
    {

        $('.dropzones').each(function () {

            // how to check dropzone exists on item?
            // or how to destroy already existed dropzone (so reinitialize after)

            $(this).dropzone({
                url: ...
            })
        });
    }

    someAjaxAdd() {
        // add new elements and with new one dropzone
        initDropzones();
    }

非常感谢

【问题讨论】:

  • 我用try catch解决了,但如果有人提供更好的解决方案我会很高兴
  • 你想知道你的dropzone中是否有文件?
  • 不,我想知道是否在元素上初始化了 dropzone。很抱歉配方不好
  • 你在文档中看到过这个初始化函数吗? dropzonejs.com/#config-init

标签: jquery dropzone.js


【解决方案1】:

你必须检查 dropzone 属性,如果它存在你可以销毁它:

function initDropzones() {
    $('.dropzone').each(function () {

        let dropzoneControl = $(this)[0].dropzone;
        if (dropzoneControl) {
            dropzoneControl.destroy();
        }
    });
}

【讨论】:

  • 你可以查看dropzoneControl == undefined
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-06-18
  • 1970-01-01
  • 2015-01-24
  • 2018-08-22
相关资源
最近更新 更多