I can not figure how to display data passed to handlabars view. here is my route.js file, which passes object to view.
var session = require('express-session');
exports.admin = function(req, res){
db.query("SELECT * FROM users", function(err, result, field){
if(err) throw err;
console.log(result);
console.log(typeof result);
res.render('page', {user: result});
});
};
and here is my page.hbs file(view)
<table>
<thead>
<th>First Name</th>
<th>Last Name</th>
<th>View Details</th>
</thead>
<tbody>
{{#each user}}
<td>{{this}}</td>
{{/each}}
</tbody>
<tbody>
{{#each user}}
<tr>
<td>{{firstname}}</td>
<td>{{lastname}}</td>
<td>{{details}}</td>
</tr>
{{/each}}
</tbody>
firstname, lastname, details are the properties of each user object
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.