2010-11-25 8 views
0
return this.each(function(){ 

    $(this).mouseenter(s,function(){ 

     s.self = $(this); 
     s.slot = $(this).attr('id').split('_')[1]; 

     s.callback = function(o){ 
      var s = {} 
      $.extend(s,o); 

      /* Ajax call, to get banner info data */       
      s.ajax = $.getJSON(domain+lng+'/banner/countbanners?slot='+s.slot,function(data){ 

       s.template = $.tmpl(s.name,$.extend(data,{ 
        slot_width:s.self.width(), 
        slot_height:s.self.height(), 
        view_href:s.view_href+s.slot 
       })); 
       s.template.appendTo(s.self); 

      }); 

     } 

     $.get_template(s); 

    }); 

    $(this).mouseleave(s,function(o){ 
     s.self.find('.banner_info_wr').remove(); 
    }); 

}); 

어떻게 mouseleave에서 s.ajax 객체에 액세스 할 수 있습니까?jQuery 콜백에서 일부 객체에 액세스

콜백은 템플릿을 얻은 후에 get_template 함수 내부에서 호출됩니다.

감사)

답변

1

mousenter (내부의 s 외부 each 콜백)을 정의하고 당신이 그것을 액세스 할 수 있습니다.

+0

주세요. 작동하지 않습니다. | – Somebody

+0

mouseleave에서 액세스하려고하면 정의되지 않습니다. Ajax 호출 바로 뒤에 콜백 내에서 mouseout을 재 바인드했습니다. – Somebody

관련 문제