var membersStatArray = [];
function runFirst (callback) {
db.group.findOne({_id: id}).then((groupFound) => {
var membersArray = groupFound.members;
membersArray.forEach(function (member) {
db.doneTodo.find({'victor._id': member._id}).then((arrayOfUserVictories) =>{
membersStatArray.push({email: member.email, victories: arrayOfUserVictories.length});
})
});
callback();
});
}
function runSecond() {
console.log(membersStatArray);
res.status(305).send();
}
runFirst(runSecond);
runFirst
中的函数是异步的,所以我打电话给控制台打印出secondFunc中的membersStatArray
,但它仍然打印[]
,我怎么能用这个回调功能?