我有以下路线:
app.get('/dashboard', passportConf.isAuthenticated, userController.getBoardsCount,userController.getSharedBoardsCount, userController.getBoards);
这是我用来从MongoDB获取值的中间件代码:
exports.getBoardsCount = function(req, res, next) {
var count = 0;
Room.count({
"owner": req.user._id
}, function(err, count) {
if (err) {
console.log(err);
}
if (count) {
req.count = count;
}
next();
console.log(count);
})
};
exports.getSharedBoardsCount = function(req, res, next) {
var sharedBoards = 0;
Room.count({
$and: [{"owner": {$ne: req.user._id}},{ users : req.user._id}]
}, function(err, sharedBoards) {
if (err) {
console.log(err);
}
if (sharedBoards) {
req.sharedBoards = sharedBoards;
}
next();
console.log(sharedBoards);
})
};
我可以使用count
在我的jade文件上显示#{count}
,但sharedBoards
虽然显示在终端中但未显示。我使用#{sharedBoards}
在我的Jade文件中显示它。你能帮帮我吗?我似乎无法找到问题所在。
答案 0 :(得分:0)
exports.getBoards = function(req, res) {
Room.find({
users: req.user._id
}, function(
err,
rooms) {
if (err) {
return err;
}
res.render('account/dashboard', {
rooms: rooms,
count:req.count,
sharedBoards:req.sharedBoards
});
});
};
我拼错了sharedBoards。