Promise.all 在批量更新数据中的应用

156 阅读1分钟
    let list: any[] = []
    this.state.selectedRowKeys.forEach((it: number) => {
      list.push(
        new Promise((resolve) => {
          resolve(update({ id: it, status: 1 }))
        })
      )
    })
    // promise.all——因为数据请求具有随机性,所以使用 promise.all 可以保证批量更新完毕后再执行后面的代码
    Promise.all(list).then((res) => {
      console.log(res, 'res')
      this.getData()
    })
  }