在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/HTML/ nodejs中forEach異步執(zhí)行怎么賦值

nodejs中forEach異步執(zhí)行怎么賦值

order_list.forEach(async (elm,index)=>{
    (order_list[index] as any).order_goods = await this.og.find({
        where:{
            order_id:elm.order_id
        }
    });
});

如代碼是不能正確賦值的

正確的寫法應(yīng)該是什么?(注:使用forEach,find操作是Promise)

回答
編輯回答
初心

forEach 的 callback 不能指定為 async 函數(shù)。

order_list.forEach((elm,index)=>{
    (async (elm,index) => {
        (order_list[index] as any).order_goods = await this.og.find({
            where:{
                order_id:elm.order_id
            }
        });
    })(elm,index);
});
2017年10月25日 12:14