I have the following parameters:
a = [{param:'a'}, {param:'b'}, {param:'c'}]
I'd like to make a get request for each parameter, like this:
a.map(function(ai){return $.get('myapi/get?ai='+ai.param)})
How do I do something once all the get requests have finished?
I have tried using $.when, like this:
$.when(
a.map(function(ai){return $.get('myapi/get?ai='+ai)})
)
.done(function(results){
results.forEach(function(ri, i){
ri.success(function(result){
a[i].result = result
}
}
do_something_with(a)
}
unfortunately I am clearly misunderstanding this $.when().done()
idiom as when I call do_something_with(a)
I don't have the new .result
attribute. I'm guessing it's because when
is seeing a single array and so just passes straight into the .done()
, as opposed to waiting for each component get
to finish.
Any help would be appreciated!