最新消息: 电脑我帮您提供丰富的电脑知识,编程学习,软件下载,win7系统下载。

Javascript等待设置对象属性

IT培训 admin 5浏览 0评论

Javascript等待设置对象属性

getStore().then((store) => {
  buildRates().then((rates) => {
    let newStore = store;
    newStore.rates = rates;
    setStore(newStore).then((res) => {
      // callback
      cb(null, res);
    })
  })
});

在async / await语法中写这个有困难。当我试着写这样的等待......

let store = await getStore();
store.rates = await buildRates();
setStore(store).then((res) => {
  // callback
  cb(null, res);
});

... setStore使用从await getStore()返回的原始对象,没有来自store.ratesawait buildRates()上的对象

有任何想法吗?

回答如下:

解决了。问题是buildRates()不是一个正确的承诺,哎呀!

Javascript等待设置对象属性

getStore().then((store) => {
  buildRates().then((rates) => {
    let newStore = store;
    newStore.rates = rates;
    setStore(newStore).then((res) => {
      // callback
      cb(null, res);
    })
  })
});

在async / await语法中写这个有困难。当我试着写这样的等待......

let store = await getStore();
store.rates = await buildRates();
setStore(store).then((res) => {
  // callback
  cb(null, res);
});

... setStore使用从await getStore()返回的原始对象,没有来自store.ratesawait buildRates()上的对象

有任何想法吗?

回答如下:

解决了。问题是buildRates()不是一个正确的承诺,哎呀!

与本文相关的文章

发布评论

评论列表 (0)

  1. 暂无评论