gpt4 book ai didi

javascript - 从js Promise获取数据

转载 作者:行者123 更新时间:2023-12-02 21:25:44 24 4
gpt4 key购买 nike

我正在执行一个返回 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com