Can send data from node database to jade
im new on nodejs i cant send data from select db to jade but work in 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 });
}
});
});
View
extends ../layout
block content
h1= title
p View All User to #{title}
p {userdata.nickname}
a(href='/user') Back to user
when i do res.send () this work, but doesn't work when i display only the title.
res.render('user/user-profil', { title: 'User Profil', userdata:results });
Am I wrong? thanks before
+3
source to share
1 answer
You are passing the array to jade, so you need to select the first element of it:
extends ../layout
block content
h1= title
p View All User to #{title}
p {userdata[0].nickname}
a(href='/user') Back to use
Otherwise, you need to use the req.models.users.findById function if you are using Mongoose for ORM.
0
source to share