我遇到一个令人沮丧的问题,我找不到原因
我的功能如下:
public async PageResult(searchRecord:Search,authorization:string,pageNumber:number,databaseName:string){
some codes .....
return new Promise((resolve,reject) => {
this._resultsDatastore.bulkInsert(
databaseName,objects
).then(succ => {
// I can see succ is printed successfully in console
console.log(succ);
// when I resolve it here I assume I am returning the result
resolve(succ)
},err => {
console.log(err);
reject(err)
})
})
}
因此您可以看到我resolve(succ),这样我就将succ返回给调用者函数
现在我有:
public async loadResults(
searchId: string,authorization: string
) {
some code....
const results = udsQuery.pages.map(async (pageNumber: number) => await this.PageResult(searchRecord,authorization,pageNumber,databaseName))
let all: any=[];
await Promise.all(results).catch(e => {
console.log("^^^^^^^^^^^^^^^^^^^^^EEEERRRRRROR^^^^^^^^^^^^^^^^^^^^^^");
}).then(res=>{
console.log("suuuuuuuuuuuuuuucesssssssssssssss");
// issue is here: below prints undefined though succ has value
console.log(res);
all.push(res);
return res;
});
}
因此,现在我在地图中调用PageResult并使用promis.all重新修改它,而不是在PageResult中返回的succ我得到了未定义的信息,请参见上面的代码:
console.log("suuuuuuuuuuuuuuucesssssssssssssss");
// issue is here: below prints undefined though succ has value
console.log(res);
我想念什么吗?