我在尝试使用调用 API 时得到的值时遇到问题。
这是我的 typescript 代码:
private async getPersonName() {
let fullName = await Api.GetName('Data($select=FullName)', `PersonId eq ${currentPersonId}`);
return fullName.value[0].Data.FullName;
}
然后,我只需使用 Jquery 将其附加到 DOM。
$("#myId").text(/*getPersonName() value*/);
当我尝试附加此内容时,它会在 DOM 中显示[object Promise]。我不太确定如何正确使用这个值。
问候。
最佳答案
试试这个$("#myId").text(await getPersonName());
或者这个:
private async getPersonName() {
let fullName = await Api.GetName('Data($select=FullName)', `PersonId eq ${currentPersonId}`);
return fullName.value[0].Data.FullName;
}
...
getPersonName().then((value) => {
$("#myId").text(value);
})
关于javascript - 在 [Object Promise] 中使用值(value),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51540545/