嘿,所以我正在使用异步系列来创建一个数组,其中包含在搜索结果中找到的用户循环遍历并查看它们是否是登录用户的好友请求数组的一部分。但是,由于某种原因,它总是结束作为假,有人注意到下面的代码有什么问题吗?
这是路由文件的代码:
exports.searchPost = function(req, res, err) {
User.find({$or:[
{firstName: req.body.firstName},
{lastName: req.body.lastName},
{email: req.body.email},
{phone: req.body.phone}]
}, function(err, users, userAdd) {
if(err) {
return res.render('searchError', {title: 'Weblio'});
} else {
if(req.body.firstName=== '' && req.body.lastName==='' && req.body.email==='' && req.body.phone=== '') {
//maybe a diff page saying that is not a valid search page
return res.render('searchError', {title: 'Weblio'});
} else {
var userAdd,
series = [];
console.log('addman');
users.forEach(function (user) {
series.push(function (callback) {
User.findById(req.signedCookies.userid, {
friendRequest: user._id
}, function () {
if (user._id === true) {
console.log('addman1');
return callback(null, [user, true]);
} else {
console.log('addman2');
console.log(user._id);
return callback(null, [user, false]);
}
});
});
});
async.series(series, function (err, results) {
//results should be an in order array of values;
console.log(results);
return res.render('searchResults', {title: 'Weblio',
userAdded: results
});
});
}
}
});
};