gpt4 book ai didi

node.js - 如何将对象传递到 Express 应用程序中的 Handlebars View

转载 作者:太空宇宙 更新时间:2023-11-03 22:24:58 27 4
gpt4 key购买 nike

我不知道如何显示传递到 handlabars View 的数据。这是我的route.js 文件,它将对象传递给 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});
});
};

这是我的 page.hbs 文件( 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 是每个用户对象的属性

关于node.js - 如何将对象传递到 Express 应用程序中的 Handlebars View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47999289/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com