function dataTransFun() {
return new Promise((resolve, reject) => {
let promises = state.listedInfo.map((info: any) => {
return getApplyForCodePara({ productId: info.productId }).then((res: any) => {
if (res.data && res.status == '1000') {
console.log('代码....')
}
});
});
Promise.all(promises)
.then(() => {
resolve(true);
})
.catch(error => {
reject(error);
});
});
}
async function saveData() {
await dataTransFun();
console.log('其他执行代码')
}
文章讲述了如何使用Promise和async/await在JavaScript中实现异步函数dataTransFun,该函数通过map遍历listedInfo并调用getApplyForCodeParaAPI,确保所有请求完成后返回true。saveData函数依赖于dataTransFun的执行结果。

被折叠的 条评论
为什么被折叠?



