2013-08-17 2 views
1

이 뷰를 컬렉션 변경 이벤트에 바인딩하여 새 아이템이 컬렉션에 추가 될 때 리셋되도록하려면 어떻게해야합니까?컬렉션 변경시이 백본보기를 어떻게 재설정 할 수 있습니까?

KAC.Views.ModuleMainNavigation = Backbone.View.extend(
    { 
     tagName: "div", 
     id: "", 
     className: "", 
     template: JST['modules/main_navigation'], 
     initialize: function() { 
      _.bindAll(this); 
     }, 
     events: { 
     }, 
     render: function() { 
      this.$el.html(
       this.template(
        { 
         collection : this.collection 
        } 
       ) 
      ); 

      return this; 
     } 
    } 
); 

답변

3

당신은 변경 이벤트를 수신해야합니다.
대부분이 기능은 initialize 기능에서 수행됩니다.

당신은 모든 이벤트 (모델 변화, 수집 리셋, 새로운 모델, 모델 제거)을 수신 할 수 중 하나

this.collection.on('add', this.render, this); 

항목 :

this.collection.on('change reset add remove', this.render, this); 

또는 단지 새로운 모델 추가 이벤트 backbone.js collection events

관련 문제