承诺所有清单

promise all with list

我正在尝试对两个列表使用 promise all,但没有得到所需的值:

只有一个列表有效:

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 添加第二个调用:

 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
  });

如何获取字符串列表?

试试这个,Promise.all 接受承诺数组 [promise],但你发送的是 [[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 => {});