Javascript 取消绑定可嵌套js事件

Javascript 取消绑定可嵌套js事件,javascript,jquery,twitter-bootstrap,bootstrap-modal,jquery-nestable,Javascript,Jquery,Twitter Bootstrap,Bootstrap Modal,Jquery Nestable,我对从Nestable js绑定的事件有问题。 我用一个使用Nestable的列表显示一个模态,问题是当我关闭模态并再次显示它时,我会重新索引事件。然后,当我尝试将元素从一个列表移动到下一个列表时,我会得到多个“dd empty”。 这是我的密码: $(function () { $('.dd').nestable({ maxDepth: 1 }); }); 这导致Nestable上的所有事件都被绑定。然后我关闭模态并再次启动它。 我想将代码附加到一个对象上,当模态再次打开或关闭时,该

我对从Nestable js绑定的事件有问题。 我用一个使用Nestable的列表显示一个模态,问题是当我关闭模态并再次显示它时,我会重新索引事件。然后,当我尝试将元素从一个列表移动到下一个列表时,我会得到多个“dd empty”。 这是我的密码:

$(function () {
    $('.dd').nestable({ maxDepth: 1 });
});
这导致Nestable上的所有事件都被绑定。然后我关闭模态并再次启动它。 我想将代码附加到一个对象上,当模态再次打开或关闭时,该对象将被破坏。 问题是事件绑定在Nestable内部,我无法手动解除绑定。 我知道一些库,比如Dragable jQueryUI,有一个销毁方法来处理这种情况,但是Nestable没有。


编辑 不管怎样,我只是找到了避免这种情况的方法,只需向库中添加一个unbind方法,每次调用Init()方法(实际上只有一次),它都会调用unbind方法,从而解决了我的问题。 代码如下: 在jquery.nestable.js内部,找到方法插件,并添加对方法unbind_events()的调用

然后,在原型中的属性init之后添加unbind方法的代码

unbind_events: function () {
            console.log("Unbind events");
            var list = this;
            list.el.data('nestable-group', this.options.group);
            list.placeEl = $('<div class="' + list.options.placeClass + '"/>');
            list.el.unbind("click");
            list.el.unbind("mousedown");
            list.el.unbind("mousemove");
            list.el.unbind("mouseup");
            if (hasTouch) {
                list.el[0].unbind('touchstart');
                window.unbind('touchmove');
                window.unbind('touchend');
                window.unbind('touchcancel');
            }
        },
unbind_事件:函数(){
console.log(“解除绑定事件”);
var list=这个;
list.el.data('nestable-group',this.options.group);
list.placeEl=$('');
列表。解除绑定(“单击”);
列表。解除绑定(“鼠标下移”);
列表解除绑定(“鼠标移动”);
列表。解除绑定(“鼠标悬停”);
如果(hasTouch){
list.el[0]。解除绑定('touchstart');
窗口。解除绑定(“触摸移动”);
window.unbind('touchend');
窗口。解除绑定(“触摸取消”);
}
},
这解决了我的问题。
问候。

由橡皮鸭解决。你能把你的编辑贴出来作为答案并做标记吗。谢谢
unbind_events: function () {
            console.log("Unbind events");
            var list = this;
            list.el.data('nestable-group', this.options.group);
            list.placeEl = $('<div class="' + list.options.placeClass + '"/>');
            list.el.unbind("click");
            list.el.unbind("mousedown");
            list.el.unbind("mousemove");
            list.el.unbind("mouseup");
            if (hasTouch) {
                list.el[0].unbind('touchstart');
                window.unbind('touchmove');
                window.unbind('touchend');
                window.unbind('touchcancel');
            }
        },