javascript - 获得承诺的结果
问题描述
我正在努力兑现承诺,到目前为止,这非常令人沮丧!
我正在控制台中调用一个方法,该方法返回这样的承诺:
getSharepointListItems("count")
调用的结果是:
Promise {<pending>}
__proto__: Promise
[[PromiseStatus]]: "resolved"
[[PromiseValue]]: Array(1)
0: {ContentTypeId: SP.ContentTypeId, Title: "400000", _ModerationComments: null, File Type: null, ComplianceAssetId: null, …}
length: 1
__proto__: Array(0)
我想将其分配400000
给一个变量并将其用于进一步计算,但我无法捕获它。
我读到我应该将 a 链接.then
到我的方法调用,我知道这也返回了一个承诺。所以我尝试了:
getSharepointListItems("PalletCounter").then( (r) => console.log(r))
现在的结果是:
Promise {<pending>}
VM1315:1
[{…}]
0: {ContentTypeId: SP.ContentTypeId, Title: "400000", _ModerationComments: null, File Type: null, ComplianceAssetId: null, …}
length: 1
__proto__: Array(0)
所以[[PromiseValue]]: Array(1)
现在已经被看起来像数组中的对象所取代,但还有一个承诺是pending
,我不明白。我仍然无法获得 400000 值/结果。链接更多.then
并没有什么不同。我仍然得到上述结果。
我该如何检索结果并将其保存到变量中?
谢谢
解决方案
推荐阅读
- azure - azure devops if else 条件
- python - 如何获取日期范围的每小时分钟数(Python)?
- node.js - 如果可以生成预签名的 url 以在 S3 对象上执行 SELECT 命令?
- javascript - 如何使用 chrome 扩展更改网站文本?
- python - 如何部署此 Web 应用程序?
- c - 为什么在 switch 中使用浮点数不起作用?
- python - 如何返回 JSON 以便可以使用点表示法访问它?
- java - 将参数传递给 java 注释
- neoscms - Neos.Form.Builder:将回复地址设置为用户填写联系表时输入的电子邮件
- plot - 当 Y 变量是一个热编码时如何解释决策树图