I have an array of values that get passed to a function. The function loops over the array and uses the values in another method.
This works fine for the first value in the array, then all other item’ I get an error: “This deferred has already been resolved”.
I would like to end up with an array of responses, it currently stops after 1 response?
Any help?
thanks!
function showQueryResults(searchResults){
function getFacIds(arr){
var def = new dojo.Deferred();
for (var i = 0, iLen = arr.features.length; i < iLen; i++) {
findParams.searchText = searchResults.features[i].attributes.ID;
findTask.execute(findParams, function(response){
def.callback(response);
});
};
return def;
};
getFacIds(searchResults).then(function(result){
console.log(result);
});
}
A
Deferredcan only be resolved once. You need to track the responses.In Dojo 1.7 syntax, assuming no errors: