gpt4 book ai didi

javascript - 具有多个异步操作的 Extjs Promise

转载 作者:行者123 更新时间:2023-11-30 15:09:52 25 4
gpt4 key购买 nike

有一个应用程序,我们必须在执行回调之前执行多个异步操作(保存 2 个商店和保存一个模型)。因此,只有当所有这些都成功时,我们才会执行一些特定的代码。当然我可以通过嵌套回调来做到这一点,但操作仍然不会异步并且(因为它们是嵌套的)并且代码变得丑陋。看到 Promises 是解决这个问题的好方法。有人可以给我一个简单的例子,说明如何在 promise 的帮助下执行多个保存操作。 reject 和 resolve 是在 model/store save 方法的回调函数中设置的。但我不明白我应该何时以及如何编写这样一个 promise 的全貌。感谢您的帮助

最佳答案

您可以使用 Promise.all (或 Sencha 的版本 Ext.Promise.all ):

The Promise.all() method returns a single Promise that resolves when all of the promises in the iterable argument have resolved or when the iterable argument contains no promises. It rejects with the reason of the first promise that rejects.

关于javascript - 具有多个异步操作的 Extjs Promise,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45267224/

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