我是 Express 框架的新手,我只是想知道如何使用 mongo DB 中的一些数据渲染 html 页面,我使用下面的代码发送 html,但不确定如何发送一些数据
res.sendFile(path + "feature.html"); this is success as html get renders
像这样发送数据?
res.sendFile(path + "feature.html", {data: data});
如何在html中显示数据?如果我发送了这样的数组
res.sendFile(path + "feature.html", {data: []});
如何在 html 中循环这个?
最佳答案
我建议你使用一些模板引擎,例如 ejs或jade 。这个表格,你可以使用res.render并发送json信息供查看。有关更多详细信息,请参阅引擎文档和 res.render
文档。
关于javascript - 使用 Nodejs Express 渲染带有数据的 html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37444090/