嵌套jQuery $ .when [英] Nested jQuery $.when
本文介绍了嵌套jQuery $ .when的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
基本上,我很想写这个:
Essentially I am tring to write this:
var async1 = $.when( a1() ).then(function(){ a2() });
var async2 = $.when( a3() ).then(function(){ a4() });
$.when(async1, async2).then(function(){
console.log("complete");
});
但是在执行a1和a3时,该函数认为自己已解决.
But at the moment when a1 and a3 have executed the function considers itself resolved.
我将相同的示例放在一个小提琴中: http://jsfiddle.net/Z7fzR/
I put together the same example in a fiddle: http://jsfiddle.net/Z7fzR/
推荐答案
您实际上从未从回调中返回由a2()
和a4()
创建的promise对象.这有效地返回了null
,显然出于$.when
目的,这算作完成:
You never actually return the promise objects created by a2()
and a4()
from the callback; this effectively returns null
, which apparently counts as a completion for $.when
purposes:
这篇关于嵌套jQuery $ .when的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文