LordZardeck
LordZardeck

Reputation: 8283

trouble with jquery deferreds

jQuery's deferred's have never liked me, and I've never been fully able to understand them. I want to be notified when a number of deferreds are ALL done. The real issue is that the number of deferreds won't be the same each time. So I can't do this:

$.when(d1, d2, d3).done()

I tried $.when.apply(this, [d1, d2, d3]) but it immediately fires when just one is completed.

Also, I absolutely need a way to pass an array of deferreds. This array is dynamic and will have a different number of deferreds each time my function executes.

I know there is probably an obvious solution, but I am oblivious to it.

Upvotes: 0

Views: 63

Answers (2)

Kory Hodgson
Kory Hodgson

Reputation: 790

UnderscorJS can do what you want, check out this: http://documentcloud.github.com/underscore/#after

Upvotes: 0

ori
ori

Reputation: 7847

Read the documentation. It clearly says you can pass one or more deferred objects to $.when.

On the other hand, if you pass an argument that's not deferred (like an array in your example) the done function will fire at once, assuming the argument is a resolved Deferred.

Upvotes: 1

Related Questions