有一个应用程序,在执行回调之前,我们必须执行多个异步操作(保存 2 个存储并保存一个模型)。因此,只有当所有这些都成功时,我们才会执行一些特定的代码。当然,我可以通过嵌套回调来做到这一点,但操作仍然不会是异步的(因为它们是嵌套的)并且代码变得丑陋。看到 Promise 是解决这个问题的一个很好的方案。有人可以向我展示一个关于如何在 promise 的帮助下执行多个保存操作的简单示例吗?拒绝和解析在模型/存储保存方法的回调函数中设置。但我不明白我应该何时以及如何编写这样一个 promise 的全貌。感谢您的帮助
最佳答案
您可以使用Promise.all
(或 Sencha 的版本 Ext.Promise.all
):
The
Promise.all()
method returns a singlePromise
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/