【发布时间】:2013-05-14 14:34:02
【问题描述】:
我刚刚开始学习使用 Backbone.js。以前我使用了一个构建在 Node.js 之上的 Web 框架来处理所有的路由和响应。有了 Backbone,就有了 SPA(单页应用程序)的可能性。
我相信我的问题与这个有关:Account for Backbone.js pushState routes with node.js express server?(express.js + 主干的问题)。
其中给出的代码:
app.get('/', function(req, res) {
// Trigger the routes 'domain.com' and 'domain.com/#/about'
// Here render the base of your application
});
app.get('/about', function (req, res) {
// Trigger the toure 'domain.com/about'
// Here use templates to generate the right view and render
});
从使用 node web 框架开始,我通常不使用 json 请求来获取数据,而是在路由关闭中查询数据库。 node.js 的工作(在 node+backbone 环境中)仅仅是提供主干页面而不是查询数据库吗?所以它只是将客户端定向到指定的backbone.js模板而不传递任何数据,然后backbone接管?
例如,如果我想显示所有书籍模型(example.com/books),我是否只需通过节点将用户发送到该 url,然后骨干网将负责查询数据库(当然是模型)?这段代码会是什么样子?
我见过的大多数主干教程都处理了外部 api。谢谢!
【问题讨论】:
标签: node.js backbone.js routing routes views