我的问题是我想访问从之前的 then() 获取的数据,我该怎么做? (要求:我无法修改 externalBuiltInFunction() )
ajaxCall(...)
.then( (response) => {
return response.json();
})
.then ( (jsonData) => {
return externalBuiltInFunction(jsonData);
})
.then ((dataFromExternalFunction) => {
... here i want to use jsonData, how can i do ?...
}
感谢帮助
最佳答案
您可以仅使用一个 then
语句与 async/await
:
ajaxCall(...)
.then(async response => {
const jsonData = await response.json();
const external = await externalBuiltInFunction(jsonData);
// Here you still have access to jsonData and external
})
关于javascript - 访问链中先前 Promise 的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56955696/