0
我無法將數據推送到組合數據數組中,而不是將數據推送到閉包函數中。我發現我需要使用與數據庫相關的程序的閉包。我是節點js的新手, javascript.and它的異步性讓我陷入了這樣的困境。任何人都可以幫助我怎麼處理這個問題。無法將數據推送到組合數據數組
combineddata=[];
if(err){
res.send(err);
}else{
for(i=0;i<data.length;i++){
(function(){
x=i;
teststats.addTestStats.find({Testid:data[x].Testid},function(err,testdata){
if(err){
res.send(err);
}else{
//console.log(testdata+"no"+x+"yes"+i);
console.log(x,i)
stat.push(testdata);
combineddata.push("examplepush");
}
});
})();
}
}
res.send(combineddata);
http://stackoverflow.com/questions/38160209/getting-parent-index-inside-a-custom- directice可以幫助你解決這個問題 – vanquishers