2013-06-25 3 views
0

이 컬렉션에 대한 컬렉션과 테이블 뷰가 있습니다.백본 모델 설정 값이 변경 이벤트를 발생시키지 않습니다.

App.Views.TableContainer = Backbone.View.extend({ 
    el: '#some-table, 

    clearTable: function(){ 
     this.collection.each(function(person){ 
      person.set('deleteMe', 1); 
     }); 
    }  
}); 

테이블의 각 행에 대한보기 : TableContainer의 clearTable 실행시

App.Views.PersonRow = App.Views.BaseViewTemplate.extend({ 
    template: template("person-row-template"), 
    tagName: 'tr', 

    events: { 
     'click' : 'removeFromTable' 
    }, 

    initialize: function(){ 
     this.model.on('change', this.removeRow(), this); 
    }, 

    removeRow: function(){ 
     console.log('removing'); 
     console.log(this.model.toJSON()); 
     if(this.model.get('deleteMe') == 1){ 
      this.$el.remove(); 
      App.publisherTableContainer.removeFromContainer(this.model); 
     } 

    }, 

    removeFromTable: function(e){ 
     var me = this; 
     this.$el.fadeOut(300); 
     App.personTableContainer.removeFromContainer(this.model); 

    } 
}); 

가 PersonRow의 함수 removeRow은 (안타깝게도) 실행되지

어떤 아이디어?

감사합니다. 로이

+0

'console.log'의 출력은 무엇입니까? –

+0

'Backbone.View.extend ({el : '# some-table,','''missing, typo가 있습니까? –

+0

이것은 오타입니다 ... – royB

답변

3

오류는 다음과 같습니다 (이것은 일반적인 하나는 아마도 왜 변경 기능이 작동하지 않을 것입니다)

this.model.on('change', this.removeRow(), this); 

가되어야한다

this.model.on('change', this.removeRow, this); 

기능에 대한 두 번째 매개 변수는해야한다 콜백 함수. 지금 당신은 removeRow에 의해 반환되는 것이 무엇이든 보내고 있습니다. 이 함수는 실제로 콜백 함수를 반환하는 경우 작동하지만이 경우에는 같지 않습니다.

+0

첫 번째 것은 오타 일뿐입니다. 그러나 문제는 확실하게 두 번째 오류에서 비롯된 것입니다. 왜 괄호를 사용하지 않아야하는지 설명하십시오. OP에 대해 명확하지 않을 수 있습니다. – Loamhoof

+0

답변을 수정했습니다. 감사합니다 Loamhoof – twibakish

관련 문제