简体   繁体   English

如何通过触发事件解除绑定

[英]How to unbind by `trigger` event

I would like to suspend a binding a point of variable as a decalaration as false . 我想暂停一个变量的绑定,因为声明为false i tried with couple of way, but not works 我尝试了几种方法,但没有用

any one help me? 有人帮我吗?

here is my code : 这是我的代码:

$(document).on('suspendSelection', this.suspendSelection.bind(this));
$(document).on('updateSelection', this.beforeStartSelect.bind(this)); //require to suspend when i get suspend selection triggered!

my try: 我的尝试:

suspendSelection : function () {

    $.unbind('updateSelection', this.beforeStartSelect.bind(this)); //not works
}
suspendSelection : function () {
            this.Update.unbind('updateSelection', this.beforeStartSelect.bind(this)) //not works
        },

If you registered some event handler on some element using on() method, then you can simply remove it using off() 如果使用on()方法在某个元素上注册了某个事件处理程序,则只需使用off()将其删除

 $(document).on('updateSelection', this.beforeStartSelect.bind(this));
 $(document).on('suspendSelection', this.suspendSelection.bind(this));

just update your suspendSelection() like this, 像这样更新您的suspendSelection(),

suspendSelection : function(){
   /* select the same element, call off() passing the event to 
      remove and the handler function you used while registering*/
   $(document).off('updateSelection', this.beforeStartSelect.bind(this));
}

Hope this helps :) 希望这可以帮助 :)

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

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