开发者

jquery ui _trigger vs trigger

开发者 https://www.devze.com 2023-03-25 07:17 出处:网络
I have developed a jquery ui-plugin and can\'t really understand which of these methods to use. According to the jquery ui documentation I should use开发者_运维百科 _trigger to trigger the events, thi

I have developed a jquery ui-plugin and can't really understand which of these methods to use. According to the jquery ui documentation I should use开发者_运维百科 _trigger to trigger the events, this allows the handlers to be initialized with the plugin like

$("#id").pluginname({ 
   click: function(){ 
      //called when clicked
   }
});

But if I later want to attach more listeners to this event I can't find any way to do that. I'm trying to use jquery bind, but that does not work. example:

$("#id").bind("click", function(){
    //This does not get fired on click if using _trigger
})

The only solution I have so far is to fire of both, but it feels kind of strange. My code must do the following to work:

$("#id").pluginname({
  click: function(){
     //called when my plugin uses this._trigger('click')
  }
}).bind(function(){
    //called when my plugin uses this.element.trigger('click')
});

I'm using custom events, but didn't think that was relevant for asking this question. Anyone have an idea on how to use event chaining when using _trigger()?


You should bind like this:

$("#id").bind("pluginnameclick", function(){


you should use this._on and this._trigger to do this so that events get cleaned op when destroying the widget.

otherwise you have to unbind the events yourself or otherwise the widget does not get cleaned up by the garbage collection of the browser

hope this answers your question

0

精彩评论

暂无评论...
验证码 换一张
取 消