Reputation: 307
I have several collections to be fetched on page load. Every collection depends on the previously loaded collection so I need to fetch them in order. This doesn't seem to be the right way to do it:
groupCollection.fetch({
success: function() {
userCollection.fetch({
success: function() {
itemCollection.fetch();
}
})
}
});
Is there a design pattern for this or am I taking a wrong approach from the beginning?
Upvotes: 1
Views: 334
Reputation: 4479
There is an option to listen to reset
event on parent collection, and load nested collection.
groupCollection.on("reset", function() {
userCollection.fetch();
});
userCollection.on("reset", function() {
itemCollection.fetch();
});
groupCollection.fetch();
Upvotes: 7