【发布时间】:2021-09-10 17:57:11
【问题描述】:
我正在尝试使用已登录用户的 Wix Velo 检索 _id 字段。代码正在运行,但是我正在使用的函数返回 [object Promise] 而不是我需要的 id 字符串。
import wixData from 'wix-data';
export function getID() {
return wixData.query("Picks") // My Collection
.eq("player", "Gary") // A field, and a cell
.find()
.then((results) => {
if (results.items.length > 0) {
let firstItem = results.items[0]._id;
console.log("Return ID: " + firstItem) // This returns the ID I need
$w("#text31").text = firstItem;
// return firstItem.toString();
} else {
console.log("No Items Found")
}
})
.catch((err) => {
let errorMsg = err;
});
}
console.log("Return the ID outside of the function: " + getID()) // This returns "[object Promise]"
我尝试使用 await,但它只会给我错误。
【问题讨论】:
标签: javascript velo