Reputation: 1692
I have this collection with an over-riden parse
method. I want a method in my view to be called when the collection is finished with parse
This collection will be calling sync
and so parse
only once.
I tried this.collection.on("reset", this.more, this);
but that doesn't work.
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);
}
Upvotes: 1
Views: 1786
Reputation: 55740
The reset method will be triggered when {reset: true}
option is passed to the fetch. You can listen to the add
and sync
that will fire this method. Also use this.listenTo
bind the events in a cleaner manner.
initialize: function() {
... some other code
this.listenTo(this.collection, "add sync", this.more);
this.collection.fetch();
}
Upvotes: 1