[英]how to pass object to handlebars view in express app
I can not figure how to display data passed to handlabars view. 我不知道如何显示传递到握手视图的数据。 here is my route.js file, which passes object to view.
这是我的route.js文件,该文件将对象传递给视图。
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) 这是我的page.hbs文件(查看)
<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 名,姓,详细信息是每个用户对象的属性
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.