我正在执行一个返回 promise 的 API 调用。该调用工作正常,但我想处理 promise 中包含的数据。这是我的电话:
let promiseArray = this.get('store').query('member', {query: term, option: this.get('option')});
promiseArray.then(members => {console.log(members);
});
let var= members;
console.log(var);
我的问题是,这不会返回我的模型的数组,即成员,成员的第二个显示也显示 undefined ,它返回一个包含大量元数据的对象,也是数组,但在一些元数据内。
我怎样才能得到简单的数组?
最佳答案
您可以使用async
await
来达到您的目的。
const promiseFunc = () => {
// Return the promise and await this inside a async function
return this.get('store').query('member', {query: term, option: this.get('option')});
}
const asyncFunc = async () => {
const value = await promiseFunc();
console.log(value);
}
asyncFunc();
关于javascript - 从js Promise获取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60746116/