i found out a cool thing in jquery:
you can do:
$.when([$.get(..), $.ajax(...), $.getJSON(...)]).then(function(data1,data2,data3){
// code to run when all requests are done
});
this is great when you want to sync many ajax calls.
in backbone an ajax call is being issued every time you fetch a model or collection:
cardsCollection.fetch();
my question is how can i achieve similar syncing capabilities with backbone model/collection fetching:
i would like to do something like:
$.when([series.fetch(), cardsCollection.fetch()]).then(function(){
cardsListView.seriesID = seriesID;
cardsListView.seriesName = series.get('seriesName');
cardsListView.template = _.template(CardsListTemplate);
cardsListView.render();
$('#loader').hide();
});
is it possible?
tnx. 😉
Yes, it’s possible. Just pass several Deferred to
jQuery.when:$.when(series.fetch(), cardsCollection.fetch()).then(...)