Javascript中的嵌套承诺

时间:2016-09-19 12:12:22

标签: javascript angularjs typescript breeze q

嵌套承诺

我使用带角度的微风,我的语言是Typescript

.then((account: IAccount) => {
     for (let i = account.workspaces.length - 1; i >= 0; i--) {
         for (let j = account.workspaces[i].apps.length - 1; j >= 0; j--) {
             appDataService.getApp(account.workspaces[i].apps[j].id)
                         **.then((app) => {
                             **apps.push(app);**
                         });**
             account.workspaces[i].apps.splice(j, 1);
         }
     }
     return account;
})
.then((account) => {
    for (let i = apps.length - 1; i >= 0; i--) {
        appDataService.deleteApp(apps[i]);
    }
    ..... // more awesome code here
    return account;
 })

我有一个嵌套的承诺

appDataService.getApp(account.workspaces[i].apps[j].id)
              .then((app) => {
                  apps.push(app); 
              });

但是当我进入下一个.then时,数组应用的长度为0.

我检查过并仔细检查过。它不是getApp函数的问题。 :)

你能解释一下如何等待那个嵌套的承诺吗?

0 个答案:

没有答案
相关问题