解析完成后,backbonejs fire事件

时间:2013-08-04 17:55:58

标签: backbone.js

我的这个集合有一个过度的parse方法。我想在我的视图中使用parse

完成集合时调用一个方法

此系列只会调用sync,因此parse只会调用一次。

我尝试了this.collection.on("reset", this.more, this);,但这不起作用。

more: function() {
        var users = this.collection.slice( this.index, this.index + this.load_once), that = this;
        this.index = this.index + this.load_once;
        _.each( users, function( user ){
            that.addOne( user );
        });
    },
addOne: function( user ){
    var view = new UserView({model: user});
    this.$("#user_list").append(view.render().el);
}

1 个答案:

答案 0 :(得分:1)

{reset: true}选项传递给fetch时,将触发重置方法。您可以收听将触发此方法的addsync。还可以使用this.listenTo以更干净的方式绑定事件。

initialize: function() {
    ...  some other code
    this.listenTo(this.collection, "add sync", this.more);
    this.collection.fetch();
}
相关问题