0
我想獲得變量外的pend變量的值並將其作爲響應發送。但是我得到了所有undefined.plz幫助 thanku提前。訪問函數外的函數變量的數據node.js
(04:55:30 IST) abhi:
app.post( '/的getData',函數(REQ,RES){
MongoClient.connect(URL,函數(ERR,分貝){
for(i=0;i<5;i++)
{
var array;
var id = "4136354161ff135631";
var cursor =db.collection('messages').find({ "_id": ObjectId(id) });
cursor.each(function(err, doc) {
assert.equal(err, null);
if (doc != null) {
pend=doc;
}
});
if(i === 5(length)){ -------------> response is sent once the loop get over
console.log(pend);
res.send(pend);
db.close();
}
}
});
});
它不發響應,我想在for循環結束後發送響應。 – Abhi
感謝subburaj快速響應..但我正在嘗試你的解決方案和響應generate.plzz幫助我如果我出錯了任何地方 – Abhi
沒有問題仍然存在.. – Abhi