Backbone.js 仅适用于单页应用程序吗?
我正在为我的 UI 寻找一个简单的架构,该架构将具有一些基本的 javascript 功能,例如:选择所有复选框、图像裁剪、一些弹出窗口和一些其他插件。
我找到了这篇文章:使用模块组织您的 Backbone.js 应用程序
我的应用程序是不是 SPA(单页应用程序)。我想知道即使我的应用程序不是 SPA,带有 jQuery 的 Backbone.js 是否会对我有帮助。
I'm searching for a simple architecture for my UI that will have some basic javascript functions in like: select all checkbox's, image crop, some pop-ups and some other plugins.
I found this article: Organizing Your Backbone.js Application With Modules
My application is not a SPA (Single Page Application). I want to know if Backbone.js with jQuery will help me even if my application is not a SPA.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Backbone 的优势实际上在于它能够管理许多模型(甚至是复杂的模型)并使渲染的页面与其当前值保持同步。它提供了 getter/setter 函数的接口,以便模型值的更改(有许多不同风格的“更改”)将调用相应视图上的渲染,并且页面将正确反映底层模型。此外,它还提供了模型上的保存、分页和路由操作的接口。
我已将 Backbone 广泛用于 SPA(它的优点)以及更传统的多页面应用程序。它没有对 UI 和 DOM 操作的特殊支持,但与 jQuery/Prototype/Zepto 结合,它可以管理它们的渲染/操作。
基本上,主干最适合理清复杂的渲染逻辑和模型更新链。如果您觉得您的应用程序有很多视图元素需要与客户端将在页面上更新的模型保持同步,那么 Backbone 是一个很好的解决方案。如果您只需要选择和操作 DOM 元素,那就有点大材小用了。仅 jQuery 就可以解决这个问题。
The strength of Backbone is really in its ability to manage many models (even complex ones) and keep the rendered page in sync with their current values. It provides an interface to getter/setter functions so that the changing of a model value (there are many different flavors of "change") will call render on the corresponding view and the page will correctly reflect the underlying models. Furthermore, it provides interfaces to saving, paging, and routing actions on models.
I have used Backbone extensively for both SPA's (where it shines) as well as more traditional, multiple page applications. It has no special support for UI and DOM manipulation, but combined with jQuery/Prototype/Zepto it manages their rendering/manipulation.
Basically, backbone works best to untangle elaborate chains of rendering logic and model updating. If you feel that your application has a lot of view elements that need to stay in sync with models that the client will be updating on the page, Backbone is a wonderful solution. If you just need to select and manipulate DOM elements, it's overkill. jQuery alone can handle that.
Backbone 实际上与您提到的内容无关,但我也不会说它严格适用于单年龄应用程序(SPA)。我想说的是,它适用于您拥有相当复杂的页面的任何情况,并且将它们分成多个部分(例如,全部从一个模型提取数据的多个视图)会对您有利。
不过,我想说 Backbone.js 的优势在于 SPA 领域。
如果您尚未在应用程序中使用 jQuery,您可能会找到一些 jQuery 片段来满足您的某些需求。然而,jQuery 是关于您提到的部分(简单的 DOM 操作、如果您使用 jQuery UI 则弹出窗口等),而不是关于结构或组织。
Backbone is really not about the things you mentioned, but I wouldn't say it is strictly for single-age apps (SPA) either. I'd say it is for any case where you've got quite complicated pages and it would benefit you to break them up into multiple pieces (for example, several views that all pull data from one model).
However, I would say the strength of Backbone.js is in the SPA realm.
You could probably find some jQuery pieces that answer some of your needs if you're not already using jQuery as part of your app. However, jQuery is all about the parts you mentioned (easy DOM manipulation, popups if you use jQuery UI, etc.) and not about structure or organization.
我相信主干的主要思想是使用 MVC 概念在复杂的应用程序中组织 JS 代码。
这样你的应用程序变得更容易维护和添加新功能,它可以轻松使用像 jasmine 这样的框架测试。
Backbone 还使基于 SPA 方法的工作成为可能(而且非常好),使用 ajax 请求服务器。它完全基于Restful理念,要得到使用backbone的代码,理解什么是Restful很重要。
基本上,骨干网有一个路由器(可以像控制器一样工作,但不是控制器)。
您可以在模型中管理应用程序的所有数据逻辑。
类似于模型列表的集合。
查看您将根据模型变化做出反应的地方。
还有其他的事情,但基本上就是这样了。
但正如我之前所说,您可以在没有 SPA 的情况下使用它。
最需要记住的是,使用backbone时必须遵循MVC的概念。如果你不这样做,那么使用backbone就没有意义。
I believe that the principal idea of backbone, is organize you JS code in complex app using the MVC concept.
This way your app becomes easier to mantain and add new features, It get easy to use frameworks tests like jasmine.
Backbone also make possible (and very good) work based on SPA approach, using ajax request to server. It is completely based on Restful concept, to get a code using backbone, is important to understand what is Restful.
Basically Backbone have a Router (that can work like a controller. but is not a controller).
Model that is where you can manage all the data logic of your application.
Collection that is like a list of models.
View that is where you will react accordingly the model changes.
There are other things, but basically, is this.
But as I said before, you can use it without have a SPA.
The most important thing to have in mind is that the concept of MVC must be followed when using backbone. If you don't do that, it doesn't make sense use backbone.