返回从循环中调用的DB查询中检索的数据时发出的问题
var getPrayerInCat = function(data){ var result ; var finalData = []; if(data.length >0){ data.forEach(function(data2){ var id= data2.id; Prayer.find({prayerCat:id},function(err,prayer){ var deferred = Q.defer() if (err) { // ... console.log('An error has occurred'); // res.send(err); result= finalData = err } else { if(!prayer){ // console.log(data2.id+'--0'); data2.prayersCount = 0; result = deferred.resolve(finalData.push(data2)) } else { // console.log(data2.id+'--'+prayer.length); data2.prayersCount = prayer.length; // console.log(prayer) result = deferred.resolve(finalData.push(data2)) } // else for data forward } deferred.promise; }) // deferred.resolve(finalData); }) /*if(finalData.length > 0) { return finalData;}*/ }}
莫回无
相关分类