nodejs Async.each嵌套循环混淆

我想有两个嵌套for循环

async.each(ListA, function(itemA,callback1){ //process itemA async.each(itemA.Children, function(itemAChild,callback1){ //process itemAChild callback1(); }), function(err){ console.log("InnerLoopFinished") } callback(); }),function(err){ console.log("OuterLoopFinished") } console.log("Process Finished") 

现在我期望根据列表大小和输出像{InnerLoopF​​inished OuterLoopF​​inished}

过程finsished

Bt我得到的是Process首先完成,InnerLoop和Outerloop消息取决于循环的大小。

我在两个循环中处理数据,所以当控制去打印“最终处理”消息,我希望我所有的数据被填充到一个对象之前,并发送它作为一个响应,而不是在这里实现

我认为不清楚工作async.each的想法可以帮助我达到预期的输出

 async.each(ListA, function(itemA,callback){ //process itemA async.each(itemA.Children/*this should be an array*/, function(itemAChild/*element of the array*/,callback1){ //process itemAChild callback1(); },function(err){ console.log("InnerLoopFinished"); callback(); }) ; } ,function(err){ console.log("OuterLoopFinished"); console.log('Process Finished'); }); 
Interesting Posts