首页 > 解决方案 > 获得承诺的结果

问题描述

我正在努力兑现承诺,到目前为止,这非常令人沮丧!

我正在控制台中调用一个方法,该方法返回这样的承诺:

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并没有什么不同。我仍然得到上述结果。

我该如何检索结果并将其保存到变量中?

谢谢

标签: javascriptpromisees6-promise

解决方案


推荐阅读