Reputation: 79
I am calling a fetch on a collection and inside its success methods fetching another collection. Once its done I am adding both the collections and rendering to the view. After I save a new item in the view, it saves in the db and after save is complete I am calling the methods that does fetching. All I want to do is to render the updated collection which now should include a newly crated model. But, When I debug step by step using chrome debugger, it gets the updated collection from the server otherwise the collection is not getting updated. I assume it is rendering before fetching. Page refresh is working just fine. Can you suggest anything I can do to change or delay rendering until fetch is complete?
Upvotes: 0
Views: 75
Reputation: 918
From the information you have given me, you should be able to do something like this.
var promises = [];
_.each(models, function (model) {
var destroying = model.destroy();
promises.push(destroying);
});
$.when.apply(null, promises).done(this.displayAllRows);
You will probably have to modify this but this should give you an idea of what you can do to destroy all your models and then render your rows.
Upvotes: 2