PgaPlayersApp.AppView = Backbone.View.extend({
el: '#pga_players_profile_app',
initialize: function()
{
//Should I do 1?
this.listenTo(PgaPlayersApp.Players, 'sync', this.addAll);
//Should I do 2?
this.listenTo(PgaPlayersApp.Players, 'reset', this.addAll);
PgaPlayersApp.Players.fetch({reset: true});
}
});
In the above code example, what is the preferred method for listening to a fetch for a collection? (sync or reset)
You should listen for 'sync'
. This is the event fired on a successful fetch operation. A 'reset'
is now only fired when an explicit collection.reset(newModels)
is called. 'sync'
is consistent between collections and models now, which is a nice consistency.
FYI: http://documentcloud.github.io/backbone/docs/backbone.html#section-93
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With