使用Node.js Express用数据渲染HTML [英] Rendering html with data with nodejs Express

查看:219
本文介绍了使用Node.js Express用数据渲染HTML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是刚开始表达框架的人,我只是想知道如何使用mongo DB中的一些数据来呈现html页面,我在下面的代码中使用了该方法来发送html,但不确定如何发送一些数据

I'm new to express framework i just want know how to render html page with some data from mongo DB i used below code to send html but not sure how to send some data

res.sendFile(path + "feature.html"); this is success as html get renders 

发送这样的数据??

res.sendFile(path + "feature.html", {data: data});

如何在html中显示数据?如果我发送了这样的数组

how to display data in html ?? if i have sent an array like this

res.sendFile(path + "feature.html", {data: []});

如何在html中循环?

how to loop this in html ??

推荐答案

我建议您使用一些模板引擎,例如 ejs 玉器.通过这种形式,您可以使用 res.render 并发送json信息以供查看.有关更多详细信息,请查阅引擎文档和res.render文档.

I suggest you to use some template engine, like ejs or jade. This form, you can use res.render and send json information for view. For more details consult the engine docs and res.render doc too.

这篇关于使用Node.js Express用数据渲染HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆