I'm trying to save several backbone models (not in a collection) and execute code after they all get saved.
This is my code simplified:
var requestsArray = modelsArray.map(function(model) {
return model.save();
});
$.when.apply(undefined, requestsArray)
.done(function() {
console.log('DONE CALLBACK');
console.log('ARGS', arguments);
})
.fail(function() {
console.log('FAILED');
console.log('ARGS', arguments);
});
But when I run this - the done
callback gets fired immediately and it doesn't wait for the ajax requests to finish.
Why is that?