0
我使用的是async npm的filterSeries,但是当我在对象上接下来调用truthy时,出于某种原因,它只传递用户而不是试图从查询中取出的部分。对象没有被传入回调
如果您发现我的代码出了什么问题,或者有更有效的方法来解决这个问题,因为我也听说,循环访问每个用户并调用查询是一个糟糕的主意,而不是执行$ in或但不知道如何。
最主要的是我想这两个文件合并后,反馈数据...
下面是代码:
exports.searchContactPost = function(req, res) {
if(req.body.searchContacts === '') { res.send('Oops you searching for nothing, well here is nothing!'); };
async.waterfall([
function(callback) {
User.find({$or:[
{firstName: req.body.searchContacts.toLowerCase()},
{lastName: req.body.searchContacts.toLowerCase()},
{email: req.body.searchContacts.toLowerCase()}]
}, function(err, users) {
if(err || users.length === 0) { res.send(err);}
callback(null, users)
});
},
function(users, callback) {
async.filterSeries(users, function(user, next) {
console.log(user);
Friend.findOne({userId: req.signedCookies.userid, friend_id: user}, function(err, friend) {
if(err) {
console.log("houston we got a problem.")
}
var object = {'fav': friend.favorites, 'notes': friend.notes, 'labels': friend.labels, 'user': user, 'status':friend.friend_status};
console.log(friend);
next(object.status === 3);
})
}, function(friendResults){
console.log(friendResults);
callback(null, friendResults);
});
}
],
function(err, results) {
res.render('contactListResults', {title: 'Weblio', friendsFound: results});
});
};
正如目前所写,很难理解你的问题和你遇到的具体问题。 – WiredPrairie
djbrick了解它 – Lion789