In my application have the following code,
initialize: function() {
Pops.Collections.TeamCollection = this.collection;
this.collection.fetch();
this.collection.on('sync', this.render, this);
},
render: function() {
this.addAll();
return this;
},
Its pretty self explanatory, fetch the collection, once it is synced with the server run the render collection. At the time of writing this sequence of code it seemed like a a good idea however it now looks like that when I save a model of the collection it runs the sync listener and runs render again. This is not the behaviour I want. Is there another listener I can use to listen for the initial fetch being complete?
According to the backbone documentation,
The event is essentially the "catch-all" for any CRUD operations communicating with the server, which is why it's being fired on saving a model. Looking deeper into the documentation gives clues as to how
.fetch()
worksBy revising your call to
this.collection.fetch({reset: true})
, the collection will load the data and fire areset
event that can be listened to instead ofsync
. This will solve your problem.