0
我是新來的nodejs for循環不能同步工作。請提前循環在節點js中無法正常工作
幫助這裏感謝是我的代碼
notifyRide:function*(body){
yield User.find({_id: {$ne: body.userId}},function(err, doc){
if(doc != null){
User.findOne({_id:body.userId},function(err, user){
Ride.findOne({_id : body.rideid},function*(err1,ride){
for (var i = 0; i < doc.length; i++) {
console.log(i)// getting 0
yield rideStatus.findOne({$and:[{receiver_id:doc[i]._id},{ride_id:body.rideid}]}, function(err, response)
{
console.log(i);//getting 1
})
}
})
})
}
})
}
難道[我的回答](https://stackoverflow.com/questions/45170956/loop-not-working-正確地在節點js/45171189#45171189)下面幫助你?任何意見? – rsp