用列表向所有人承诺 [英] promise all with list
本文介绍了用列表向所有人承诺的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将 promise all 与两个列表一起使用,但没有获得所需的值:
I'm trying to use promise all with two list, and I'm not getting the desired values:
只有一个列表就行了:
this.firstService.getAll()
.then(dataR => {
//dataR = ['data':{'data1': 'one-one', 'data2': 'one-two'},
// 'data':{'data1': 'two-one', 'data2': 'two-two'}]
return Promise.all(
dataR.data1.map(x =>
this.secondService.getReadURL(
x.one))
}
).then(dataR2 => {
//dataR2 is a list of strings
});
现在我正在尝试使用 data2 添加第二个 promise 调用:
Now I'm trying to add a second call in promise with data2:
return Promise.all(
[dataR.data.map(x =>
this.secondService.getReadURL(
x.data1)),
dataR.data.map(x =>
this.secondService.getReadURL(
x.data2))]
}
).then(dataR2 => {
//dataR2 is a list of list of zoneAwarePRomise
});
如何获取字符串列表的 lis?
How can I get lis of list of strings?
推荐答案
试试这个,Promise.all 接受一个promise数组[promise]
,但是你发送的是[[promise],[承诺]]
.
try this, Promise.all accept an array of promise [promise]
, but you are sending [[promise],[promise]]
.
var promises = dataR.data.map(x =>
this.secondService.getReadURL(
x.data1));
promises = promises.concat(dataR.data.map(x =>
this.secondService.getReadURL(
x.data2)));
return Promise.all(promises).then(data => {});
这篇关于用列表向所有人承诺的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文