I have array of some data, let's say Cities. In the loop I execute some async call (let's say to bring the streets) to get the promise. I mark the city object as done or fail depends on promise status. Once all cities' promises are done, I want to execute function that render the data depends on the status of the promise, either true or false.
Here what I have tried:
---------------------------------------------------
var promises = [];
$.each(Cities, function (key, value) {
var city = this;
var streets = .... ajax call
promises.push(streets);
streets.done(function (result) { city.succeed = true; }).fail(function () { city.succeed = false; });
});
$.when.apply($, promises).always(ShowCitiesWithStreets);