Backbone.js 中的控制器与应用程序级视图
我正在尝试使用 Backbone.js,我正在尝试解决的问题之一是人们如何在 Backbone 中有效地使用控制器。
我注意到控制器是后来添加到框架中的,并且视图具有大量的控制器逻辑只是因为浏览器和 DOM 的设置方式。 Backbone 网站上的 TODO 列表示例也是在没有控制器的情况下实现的。
所以我只是不清楚如何使用主干的控制器方面。如果有人能够阐明这个主题,我将非常感激。
谢谢! 马特
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Backbone.View 和 Backbone.Controller 之间的区别在于,Controller 具有路由架构和相应的 Backbone.History() 侦听器,该侦听器关注 URL 中井号标记 (#) 之后的部分。
从根本上来说,这意味着 Backbone.Controller 提供可添加书签的 URL。因为您可以手写哈希部分,并将它们添加为书签,所以 Bookmark.Controller 应该仅引用对其显示 GETtable 项有意义的对象。
我写了一个小教程,http://www. elfsternberg.com/2010/12/08/backbonejs-introducing-backbone-store/,Backbone Store 的 Sammy 教程的移植版。如果您点击 GitHub 存储库的链接,您还可以获得最新版本。
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.com/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.