2016-07-26 87 views
1

我有一个JavaScript函数,我正在进行一些其他调用,并使用响应为下一次调用构建有效负载。下面是一些sudo代码,显示了我正在尝试执行的操作。我所有的代码工作正常;但是,我不知道如何将承诺p3返回给updateList调用方。我非常感谢任何帮助,谢谢。如何返回嵌套的承诺

function updateList(listOfUsers){ 
    var p1 = getUser(userId1); // returns a promise  
    var p2 = getUser(userId2); // returns a promise 
    $q.all([p1, p2]).then(function success(){ 
     ...some code to get the uses and build payload for next call... 
     var p3 = updateList(payload); //also returns a promise 
     //how do I return p3? 
    }); 
} 

-dj

回答

1
function updateList(listOfUsers){ 
    var p1 = getUser(userId1); // returns a promise  
    var p2 = getUser(userId2); // returns a promise 
    return $q.all([p1, p2]).then(function success(){ 
     ...some code to get the uses and build payload for next call... 
     return updateList(payload); //also returns a promise 
    }); 
} 
0

因此,这是嵌套的承诺是如何工作的,我只好在解析功能也

return $q.all([p1, p2]).then(function success(){ 
     ...some code to get the uses and build payload for next call... 
     return updateList(payload); //also returns a promise 
    }); 
回报