检查是否已附加 Dropzone

Check if Dropzone is already attached

页面上的拖放区很少,ajax 加载了新项目,因此我需要检查该项目是否已附加拖放区

    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();
    }

非常感谢

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

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

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