【发布时间】:2016-01-23 22:38:10
【问题描述】:
我有以下路线:
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 文件中显示它。你们能帮我解决这个问题吗?我似乎找不到问题所在。
【问题讨论】:
-
看起来您的路线在
passportConf.isAuthenticated之后缺少逗号? -
我刚查了一下,那里有个逗号。我在这里写的时候错过了。编辑我已经用逗号更新了上面的 sn-p。
-
没人帮我吗?我敢肯定这一定很傻
-
Jade 文件的渲染代码在哪里?
-
渲染代码是什么意思?抱歉,我对这个堆栈很陌生。
标签: node.js mongodb express pug