类似 MVC 的代码在 Node.js 中如何工作?
我开始了解 Node.js,并试图弄清楚如何执行正常的 MVC 操作。例如,下面是一个 Django 视图,它从数据库中提取两组记录,并将它们发送到模板中进行渲染。
def view(request):
things1 = ThingsOne.objects.all()
things2 = ThingsTwo.objects.all()
render_to_response('template.html, {'things1': things1, 'things2': things2})
类似的 Node.js 函数会是什么样子?
I'm starting to get my head around node.js, and I'm trying to figure out how I would do normal MVC stuff. For example, here's a Django view that pulls two sets of records from the database, and sends them to be rendered in a template.
def view(request):
things1 = ThingsOne.objects.all()
things2 = ThingsTwo.objects.all()
render_to_response('template.html, {'things1': things1, 'things2': things2})
What might a similar node.js function look like?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
http://boldr.net/mvc-stack-node-js-ejsgi -scylla-mustache 是一篇很棒的小文章,其中包含使用不同 Node 模块的 MVC 模式的完整 github 示例。它还列出了当前可用的替代模块。它比 http://howtonode.org/ 更好地回答了我这个问题,后者有一些很好的建议,但我不能在那里找到有关 MVC 的任何内容。
http://boldr.net/mvc-stack-node-js-ejsgi-scylla-mustache is a great little article with a full github example of a MVC pattern using dirfferent Node modules. It also lists alternate modules currently available. It answered this question for me better than http://howtonode.org/ which has some good tuts but I couldn't find anything on MVC there.
最简单的方法是使用expressjs,它是 Node.js 的 MVC 框架。 Node 顾名思义,就是用于网络的事件化 I/O。
http://expressjs.com 上的示例应该有助于基础知识,但可以直接回答您的问题。
The easiest way to do this is with expressjs, which is an MVC framework for Node. Node is just what it says, evented I/O for the web.
The example on the http://expressjs.com should help with the basics but to answer your question directly.
TowerJS 是一个流行的 MVC 框架,基于
站点 http://towerjs .org/
来源https://github.com/viatropos/tower
TowerJS is a popular MVC framework based on
Site http://towerjs.org/
Source https://github.com/viatropos/tower
RailwayJS是一个MVC框架,基于ExpressJS用JavaScript编写,运行在nodeJS平台上。它的灵感来自于 Ruby on Rails 框架。您可以在这里了解RailwayJS的MVC架构:http://jsmantras.com/blog/RailwayJS-Routing
RailwayJS is a MVC framework, written in JavaScript based on ExpressJS and runs over nodeJS platform. It is inspired by Ruby on Rails framework. You can read about MVC architecture of RailwayJS here: http://jsmantras.com/blog/RailwayJS-Routing