【发布时间】:2021-12-25 23:58:48
【问题描述】:
我想使用 express 将 server.js 中的一个元素添加到我的 html 文件中的表中。我知道您可以在 html 文件中使用像“{{example}}”这样的双花括号来使用res.render(views, options) 从服务器文件中导入一个值。但我想知道是否有办法向这样的表添加新行:
index.html:
<table>
<tr>
<th>Description</th>
<th>Adress</th>
</tr>
<tr>
<td>{{description}}</td>
<td>{{adress}}</td>
</tr>
</table>
每次我调用我的res.render() 方法时都会添加一个新行。这是我的服务器文件中的内容:
server.js:
app.get('/index', (req, res) => {
var values = []
var cursor = dbo.collection('collection').find()
cursor.forEach(function (doc, err) {
if (err) throw err;
values.push(doc.name);
values.push(doc.adress)
}, function () {
res.render('index', {description: values[0], adress: values[1]})
})
})
【问题讨论】:
标签: javascript html express express-session