2013-06-25 138 views
0

我有這個集合的集合和表視圖。骨幹模型設置值不會觸發更改事件

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

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

在表中每一行的視圖:

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); 

    } 
}); 

執行clearTable TableContainer時,代碼PersonRow的功能removeRow沒有執行(可悲)

任何想法?

謝謝! 羅伊

+0

'console.log'的輸出是什麼? –

+0

'Backbone.View.extend({el:'#some-table,',有一個報價'''丟失,錯字? –

+0

它是一個錯字... – royB

回答

3

錯誤是:(這是一種常見的一個可能就是你的改變功能無法正常工作)

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

應該是:

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

上功能第二個參數應該是一個回調函數。現在你正在發送removeRow返回的任何內容。這將工作,如果該功能實際上是返回一個回調函數,但我想這不是在這種情況下:)

+0

第一個肯定只是一個錯字,不需要但他的問題肯定來自第二個錯誤,解釋爲什麼它應該沒有括號,但可能不清楚OP。 – Loamhoof

+0

我已經編輯了答案。謝謝Loamhoof – twibakish

相關問題