我正在为nodejs使用优秀的caolan“异步”模块:
我有这个代码:
exports.manageComments = function(req, res) {
var toDeleteIds = [];
var deleteFunctions = [];
if (req.body.doDelete) {
toDeleteIds = req.body.doDelete;
}
var i;
for ( i = 0; i < toDeleteIds.length; i++ ) {
var deleteFunction = function(callback) {
var id = toDeleteIds[i];
console.log(id);
Comment.findOne({_id:id}, function(err, found) {
if (!err) found.remove(callback);
});
}
deleteFunctions.push(deleteFunction);
}
async.parallel(
deleteFunctions,
function(err,results) {
exports.comments(req, res); //render a view
}
);
};
我的数组包含两个元素,但 console.log() 一直告诉我“未定义”。
我错过了什么?