문제

I am unable to access parent object with in the event handler of the object!

I am creating a widget:

(function( $ ) {

  $.widget('cs.window',{

     _create:function(){
       var me = this;
       this.append('<div class="close">X</div>');
       var close = this.element.find('.close');
       close.bind('click',function(){
        alert($(this));// this is referring event handler here
                       //but how to access `me` object here
        me.element.hide();//I want to achieve this, about but its saying me is undefined
      });
     }
  });

}(jQuery));

How to use me object in the click event handler?

도움이 되었습니까?

해결책

If you bind a function with this._on then the this inside the callback is the widget itself. Try:

this._on(close, {
    click: function(){ this.element.hide(); }
});
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top