2014-04-03 2 views
0

내가보기백본 이벤트는

app.View.FriendRequestButtonView = Backbone.View.extend({ 

     initialize: function() { 
      this.set(a, b, c); 
      app.on('foo', this.reject, this); 
      app.on('boo', this.accept, this); 
    }, 

    reject: function(){ 
      this.set(false, false, false); 
    }, 

    accept: function(){ 
      this.set(true, false, false); 
    }, 

    set: function (a, b, c){ 
     if(!a && b && c){ 
      this.events = { 
       "click .cancel": "dosomething" 
      }; 
      this.render(); 
     } 
     } 
     ........ 
    } 

있습니다. 내가 뭘 잘못하고있어?

답변

1

보기의 events은 초기화 중에 바인딩됩니다. 나중에 설정하면 작동하지 않습니다. 수동으로 바인딩 delegateEvents 전화 : 의미

If an events hash is not passed directly, uses this.events as the source. 

는 다음과 같은 작동합니다 :

this.events = { 
    "click .cancel": "dosomething" 
}; 
this.delegateEvents(); 

this.render();