categoryModel.where({"parent_id":null}).exec(function(err,docs){ var list=new Array(); var father=[],children=[]; docs.forEach(function(doc,index){ father._id=doc._id; father.name=doc.name; father.childrens=[]; list.push(father); list[index].childrens.push(doc);//我是测试一 categoryModel.where({"parent_id":doc._id}).exec(function(err,docs2){ docs2.forEach(function(doc2,index2){ children._id=doc2._id; children.name=doc2.name; //list[index].childrens.push(doc2);//我是测试二 }); }); }); console.log(list); });
如上,一个查询中内置了其相关的查询,在上面的2个测试中,测试一的可以加入到数组list的childrens中,而测试二的不能加入到数组list的childrens中,请问这是神马情况,该如何解决呢?!!!!!!!!!