2009-10-14 5 views
0

왜 이것이 실행되지 않습니까?jQuery 맞춤 이벤트

$('#nav').bind('app:event', function (event, status) { 
    console.log([event, status]); 
}); 

이 때 : 플러그인 내에서

$(this).trigger('app:event', [options]); 

:

$(document).bind('app:event', function (event, status) { 
    console.log([event, status]); 
}); 

이벤트 트리거가 사용 중이다.

이 전체 블록 :

/* App.js */ 
$(function ($) { 

    // UI Panels 
    $('#panels').panels({ 
    controls: '#nav a' 
    }); 

    $('#nav').bind('app:event', function (event, status) { 
    console.log([event, status]); 
    }); 

}); 

/** 
* Plugin dir 
*/ 
(function($) { 
    // Interface 
    $.fn.panels = function (options) { 
    var settings = {}, current; 

    if (options) { 
     $.extend(settings, options); 
    } 

    // Setup 
    $('.panel', this).hide(); 
    $('.panel:first', this).slideDown('slow'); 

    return this.each(function() { 
     var self = $(this); 

     $(settings.controls).click(function() { 
     // Get reference 
     current = this.href.substring(this.href.indexOf('#') + 1); 

     // Hide all 
     $('.panel', self).hide(); 
     // Show current 
     $('#'+ current) 
      .publish({    
      'panelReady': current 
      }) 
      .slideDown(); 

     return false; 
     }); 
    }); 
    }; 

    // Publish event 
    $.fn.publish = function (options) {  
    var settings = { 
     origin: this  
    }; 

    if (options) { 
     $.extend(settings, options); 
    } 

    return this.each(function() { 
     $(this).trigger('app:event', [options]); 
    }); 
    }; 

}(jQuery)); 

나는 #ID 주위 $(document).ready()을 넣어 이벤트에

+1

$ ('# nav') 주변에 $ (document) .ready()가 있습니다. bind()? – powtac

답변

0

시도를 구독 할 수있는 솔루션과 같은 suplish/가입/관찰자처럼 뭔가를 구현하기 위해 노력하고있어 .

$(document).ready(function() { 
    $('#nav').bind('app:event', function (event, status) { 
      console.log([event, status]); 
    }); 
}); 
+0

아니, 안 했어, 이미 $ (function ($) {}) 안에있다. 하지만 그것을 $ (document) .ready(); 아무것도 바뀌지 않았다. –

0

코드가 너무 적어서 말하기 어렵습니다. $ ("# nav")를 트리거하려고 할 때 $ (this)를 참조 하시겠습니까?

+0

전체 블록을 추가했습니다. –