I'm using a code like the following.
var firstCollection = new FirstCollection();
$.when( firstCollection.fetch( params1 )).done(function() {
// here firstCollection has been enriched. It contains the actual data.
// params2 will depends on firstCollection attirbutes
var secondCollection = new SecondCollection();
$.when( secondCollection.fetch( params2 ) ).done(function() {
// here secondCollection has been enriched. It contains the actual data.
// move to another screen
}).fail( function() {
} );
}).fail(function() {
}).always(function() {
});
My goal is to perform two calls in sequence, i.e. perform the fetch of the firstCollection
and then the fetch of secondCollection
. The motivation is that second fetch depends on firstCollection
attributes.
So my question is the following. Is there any better alternative to achieve this with jQuery Deferred or the solution I'm using is correct?