Why my array of functions is not triggered?
Edit: Still nothing:
var actions = [];
$.each(data, function(i, v) {
actions.push(new Promise(function(resolve, reject) {
if (_this.apiConversatiosGet(v.app_id)) {
resolve();
}
}));
});
$.when(actions).done(function() {
console.log("done");
});
and:
apiConversatiosGet: function ($app_id)
{
var _this = this;
return $.ajax({
url: "/api/conversations/" + $app_id,
type: "get",
success: function (data) {
console.log("ajax");
$.each(data, function (i, v) {
_this.contactBox.append(v);
});
}
});
}
as a result in console I got:
done (4) ajax
and should be opposite
$.whenshould accept an array ofdeferredobjects. When you push to the array, you need to execute each function and return a deferred (if they all execute ajax calls, you could just return the result of the ajax call).