离线使用 Backbone.js
我正在评估 Backbone.js 在我的 Web 应用程序中保持数据和 UI 同步。然而,Backbone 的大部分价值似乎在于它对 RESTful 接口的使用。尽管我将来可能会添加服务器端备份,但我的主要用例涉及使用 HTML5 本地存储离线存储所有数据。
对于这样的用例来说,Backbone 是否太过分了?如果是这样,是否有更好的解决方案,只专注于数据更改时更新 UI,反之亦然? (我也在研究 Knockout 和 Javascript MVC。)
编辑:我现在也在研究 Angular.js和 jQuery 数据链接。
I'm evaluating Backbone.js for keeping data and UI synchronized in my web app. However, much of Backbone's value seems to lie in its use of RESTful interfaces. Though I may add server-side backup in the future, my primary use case involves storing all data offline using HTML5 local storage.
Is Backbone overkill for such a use case? If so, is there a better solution, focused solely on updating UI when data changes, and vice versa? (I'm also looking into Knockout and Javascript MVC.)
EDIT: I'm also now looking into Angular.js and jQuery Data Link.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
Backbone.js 与本地存储的配合与 RESTful 查询的配合一样好。
我是一个通过示例学习的人,所以这里有一些帮助您入门的链接:
Todos,一个待办事项应用程序
使用本地存储和
backbone.js,查看 带注释的
源看看它是如何工作的。
本地存储适配器是
开始所需的一切,请采取
查看 带注释的来源
也是如此。
Backbone.js works just as well with local storage as it does with RESTful queries.
I'm a learn-by-example kind of guy so here are some links to get you started:
Todos, a todo application
that uses local storage and
backbone.js, check out the annotated
source to see how it works.
The localStorage adapter is
all you need to get started, take a
look at the annotated source of
that too.
在过去的几周里,我针对与您的情况接近的情况评估了不同的解决方案;作为一个在我个人空闲时间完成的项目,而不是一个优秀的 Javascript 程序员,我所需要的只是一些易于学习的东西,以避免从头开始。
毫不奇怪,我有相同的候选者:Backbone.js、Javascript MVC 和 Knockout.js。
Backbone.js 获胜:
Backbone.js 是轻量级的并且相对没有魔法;您可能会使用其功能的一小部分,但它为开发您的解决方案提供了坚实的基础。
In the past weeks I have evaluated different solution for a scenario close to yours; being a project done in my personal free time and not being a good Javascript programmer, all I needed was something easy to learn to avoid starting from scratch.
Not surprisingly, I had the same candidate: Backbone.js, Javascript MVC and Knockout.js.
Backbone.js won:
Backbone.js is lightweight and relatively magic-free; you will probably use a small subset of its feature but it provieds a solid base to develop your solution.
我知道已经有一段时间了,但您可能想查看 github 上的骨干离线项目: https://github .com/Ask11/backbone.offline
I know it's been a while but you may want to check out backbone-offline project on github: https://github.com/Ask11/backbone.offline
您还可以查看 AFrameJS。我创建了一个简单的概念证明笔记应用,可以离线使用使用 HTML5 WebSQL 规范,但还想创建一个也使用 localStorage 的适配器。我个人的观点(我有偏见)是,从长远来看,使用任何类型的 MVC 库都会对您有所帮助 - Backbone、Knockout 和 AFrame 等库的价值在于它们能够减少 MVC 的认知负担开发人员通过强制实施良好的关注点分离。数据相关的功能驻留在模型中,显示数据驻留在视图中,而粘合剂则保留在控制器中。乍一看,分离这三个概念可能看起来很迂腐,但最终的结果是代码更容易开发、更容易测试、更容易维护、更容易重用。有关使用 AFrameJS 的基本教程可以在我的网站上找到:http:// www.shanetomlinson.com/2011/aframejs-tutorial-for-noobs/
You can also take a look at AFrameJS. I have created a bare-bones proof of concept note-taking app that works offline using HTML5 WebSQL spec, but also want to create an adapter that uses localStorage as well. My personal opinion (and I am biased) is that using an MVC library of any sorts is going to help you in the long run - the value of libraries such as Backbone, Knockout, and AFrame lie in their ability to reduce the cognitive load of the developer by enforcing a good separation of concerns. Data related functionality reside in models, displaying that data resides in Views, and the glue is kept in Controllers. Separating these three concepts might seem pedantic at first, but the end result is code that is easier to develop, easier to test, easier to maintain, and easier to reuse. A basic tutorial on using AFrameJS can be found on my site at: http://www.shanetomlinson.com/2011/aframejs-tutorial-for-noobs/