我是nodejs上的新手,不能从select db向jade发送数据,但可以在json中工作。
router.get('/view-profil', function(req, res, next){
req.models.users.all({id:16}, function(err, results) {
if (err) {
res.send({
status:'error',
data:err
});
} else {
res.send({
status:'ok',
data:results
});
console.log(results)
// results.forEach(function(data){
// console.log(data);
// });
// res.render('user/user-profil', { title: 'User Profil', userdata:results });
}
});
});视图
extends ../layout
block content
h1= title
p View All User to #{title}
p {userdata.nickname}
a(href='/user') Back to user当我执行res.send()时,这项工作不起作用,但当我渲染时,只显示标题。
res.render('user/user-profil', { title: 'User Profil', userdata:results });我错了吗?谢谢你之前
发布于 2015-04-30 18:36:26
您正在将一个数组传递给jade,因此您需要选择它的第一个元素:
extends ../layout
block content
h1= title
p View All User to #{title}
p {userdata[0].nickname}
a(href='/user') Back to use否则,如果您使用Mongoose进行对象关系映射,则需要使用函数req.models.users.findById。
https://stackoverflow.com/questions/29965432
复制相似问题