我如何在外部使用 promise 的答案。那我该怎么办?
arreglo.forEach((item) => {
if (item.tipoCampo == 3) {
self.campoSelects(item.tablaCampo)
.then(resp => {
console.log(resp)
})
.catch(e => console.log(e))
}
});
.then () 内的 console.log (resp) 知道它并正确打印,但是当我想知道 forEach 中的 resp 以便在下面使用时,它显示未定义 谢谢。
最佳答案
arreglo.forEach((item) => {
if (item.tipoCampo == 3) {
self.campoSelects(item.tablaCampo)
.then(resp => {
logMyData(resp);
})
.catch(e => console.log(e))
}
});
logMyData=(x)=>{
console.log(x);
}
这就像添加一个在 .then 中执行的辅助函数一样简单
关于node.js - 在外面使用answer .then()并在node js中的另一部分代码中使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54947096/