javascript - 使用 Nodejs Express 渲染带有数据的 html

标签 javascript html node.js mongodb express

我是 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 中循环这个?

最佳答案

我建议你使用一些模板引擎,例如 ejsjade 。这个表格,你可以使用res.render并发送json信息供查看。有关更多详细信息,请参阅引擎文档和 res.render 文档。

关于javascript - 使用 Nodejs Express 渲染带有数据的 html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37444090/

相关文章:

javascript - 绝对位置元素向左或向右取决于它在哪里?

javascript - three.js obj 和 mtl 文件呈现黑色并带有阴影

html - 聚合物纸抽屉面板响应式设计

node.js - 未捕获、未指定的 "error"事件

node.js - 需要 Node 中的 Mongoose

javascript - 打开一个新窗口并关闭另一个窗口

javascript - 如何克服 "Error calling method on NPObject"并 Play() a SWF?

javascript - 如何更改脚本以仅加载页面内容而不加载图像等?

javascript - 如何在 tinyMCE 中自定义单个文本区域

javascript - 如何使用用于测试自动化的 JavaScript 查找具有相同属性的两个 Web 对象