最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Controllers vs. App-level View in Backbone.js - Stack Overflow

programmeradmin1浏览0评论

I'm trying to pick up Backbone.js and one of the issues I'm trying to work through is how people use controllers effectively in Backbone.

I noticed that controllers were added later in the framework, and that views have a significant amount of controller logic just because of the way the browser and DOM are set up. Also the TODO list example on Backbone's website is implemented without a controller.

So I'm just unclear on how to use the controller aspect of backbone. If anyone could shed some light on this topic I'd really appreciate it.

Thanks! Matt

I'm trying to pick up Backbone.js and one of the issues I'm trying to work through is how people use controllers effectively in Backbone.

I noticed that controllers were added later in the framework, and that views have a significant amount of controller logic just because of the way the browser and DOM are set up. Also the TODO list example on Backbone's website is implemented without a controller.

So I'm just unclear on how to use the controller aspect of backbone. If anyone could shed some light on this topic I'd really appreciate it.

Thanks! Matt

Share Improve this question asked Feb 6, 2011 at 19:50 MattMatt 23k25 gold badges85 silver badges118 bronze badges 1
  • jamesyu/2011/01/27/… – Heikki Commented Feb 6, 2011 at 19:56
Add a ment  | 

1 Answer 1

Reset to default 12

The difference between a Backbone.View and a Backbone.Controller is that the Controller has the routes architecture, and the corresponding Backbone.History() listener, which pays attention to the part of the URL after the hash tag (#).

Fundamentally, this means that a Backbone.Controller provides bookmarkable URLs. Because you can hand-write the hash portion, and bookmark them, the Bookmark.Controller should only refer to objects for which it makes sense to display a GETtable item.

I've written a little tutorial, http://www.elfsternberg./2010/12/08/backbonejs-introducing-backbone-store/, a port of the Sammy tutorial of The Backbone Store. If you follow the link to the GitHub repository, you can also get the latest version.

发布评论

评论列表(0)

  1. 暂无评论