gpt4 book ai didi

jquery - 从 Deferreds 数组中提取值

转载 作者:行者123 更新时间:2023-12-01 05:01:16 25 4
gpt4 key购买 nike

我有一个延迟对象数组,我试图在它们完成后将其映射到它们的解析值。我想在一切完成解析后返回数组。

这是我到目前为止所拥有的:

$.when.apply(null, deferredArray)
.pipe(function(){
return deferredArray;
});

不幸的是,这会返回处于已解析状态的延迟对象数组。有什么方法可以直接访问已解析的元素吗?我知道我可以将 .then.pipe 分别链接到已解析的延迟对象数组上,但这对于我的目的来说效果不佳。

最佳答案

延迟对象并非旨在返回任何值。您必须在回调中处理结果。

结果作为参数传递给 donefailpipe 回调:

$.when.apply(null, deferredArray).then(function(){
// arguments[0] is the result of the first deferred object
// arguments[1] is the result of the second deferred object
// ...

// or simple pass it to a function that needs the results:
someFunction(arguments);
});

当然,您也可以将该函数设置为回调:

$.when.apply(null, deferredArray).then(someFunction);

DEMO

关于jquery - 从 Deferreds 数组中提取值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9845997/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com