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

    }
});

执行 TableContainer 的 clearTable 时,PersonRow 的函数 removeRow 没有执行(遗憾)

有任何想法吗?

谢谢!罗伊

4

1 回答 1

3

错误是:(这是一个常见的错误,可能是您的更改功能不起作用的原因)

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

应该:

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

on functions 第二个参数应该是一个回调函数。现在,您正在发送 removeRow 返回的任何内容。如果该函数实际上返回一个回调函数,这将起作用,但我想它不是在这种情况下:)

于 2013-06-25T08:50:20.457 回答