0
有没有办法来运行代码顺序在node.js中的,我试图运行下面的代码和它,我的鼻涕如预期工作如何实现代码顺序流
for(var i =0; i < userList.length; i++) {
console.log("============userList========="+userList[i]);
Db.findOne({"_id" : Number(userList[i])}, { "flag" : 1 }, function(err, result) {
if(result && (result.get("flag.notify") === true)) {
console.log("========my condition========="+result);
}
});
}
console.log("===reached here===");
callback(null, MyResult);
我想要的上面的代码来迭代和检查数据库中的条件,但这不会发生在这里。任何线索?
代码实际上是不是迭代或者你只是想在callback()之前完成检查? – 2013-04-09 11:38:48
假设@AndreasHultgren是正确的,请查看使用'async'库的['each'](https://github.com/caolan/async#eacharr-iterator-callback)或'eachSeries'方法。很多关于这个话题的现有问题。 – JohnnyHK 2013-04-09 11:57:03