有人可以帮助我为什么promise.all中的承诺,即(suggestRC和suggestGL)没有被调用?我想确保suggestRC和suggestGL同时执行。这就是原因,我写的是这样的。 extractIdeas被调用但是suggestRC和suggestGL没有被调用。
function suggestValues(editIdeaPanel) {
Requests.deckreposvc({searchIdeas: {searchString: searchReq}})
.then(extractIdeas)
.then(Promise.all([suggestRC, suggestGL]))
.catch(handleError);
}
function extractIdeas(searchRes) {
return searchRes.searchIdeas.data;
}
function suggestRC(ideas) {
return new Promise(function(resolve, reject) {
//do something
}
resolve(ideas);
});
}
function suggestGL(ideas) {
return new Promise(function(resolve, reject) {
if(!editIdeaPanel.wdGLeaderCombo.propertyValue.uuid) {
//do something
}
resolve(ideas);
});
}
答案 0 :(得分:3)
您需要在传递给then
的回调中调用这两个函数(添加括号):
.then(data => Promise.all([suggestRC(data), suggestGL(data)]))
此外,您需要 suggestValues 到return
承诺:
return Requests.deckreposvc( //...etc