本文介绍了Backbone.js的能够做到的休息和localStorage的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试与Backbone.js的(https://github.com/jeromegn/Backbone.localStorage)的localStorage的模块。据我所知,这个重载Backbone.sync,因此停止从推到服务器骨干网(?)。理想情况下,我想通过我的数据传回服务器,以及本地和坚持它的在线时,只需使用localStorage的离线的时候(你知道,完美的应用程序)。我还没有发现任何文件呢。

I have been experimenting with the localstorage module for Backbone.js (https://github.com/jeromegn/Backbone.localStorage). As I understand it this overloads Backbone.sync and therefore stops backbone from pushing to the server(?). Ideally, I would like pass my data back to the server as well and persist it locally when online and just use localstorage when offline (you know, the perfect app). I haven't found any documentation yet.

时Backbone.localStorage这项工作的一部分?
任何人都已经能够建立这种情况?
如何做到这一点? (请告诉我,我没有推出自己的。)

Is Backbone.localStorage a part of this?Has anyone been able to build this scenario? How is this done? (Please tell me I don't have to roll my own.)

感谢。

推荐答案

Backbone.localStorage是你可以使用覆盖Backbone.Sync外部文件。

Backbone.localStorage is an external file you can use which overwrites Backbone.Sync.

您可以使用简单的功能检测用户是否在线或离线,然后异步加载Backbone.localStorage.js如果它们是离线的。

You can use simple feature detection for whether the user is offline or online and then asynchronously load Backbone.localStorage.js if they are offline.

如果您neccesary也可以通过在 Backbone.sync的特定版本为您的模型和集合。

If neccesary you can also pass in a specific version of Backbone.sync to your models and collections.

如果你想在你就得写你自己的版本Backbone.sync的两个呼叫服务器和呼叫localStorage来同时做两件事。

If you want to do both at the same time you'll have to write your own version of Backbone.sync that both calls the server and calls localStorage.

要做到这一点,最简单的方法是只定义

The easiest way to do this is to just define

Backbone.sync = function() {
    originalSync.apply(this, arguments);
    localStorageSync.apply(this, arguments);
}

编辑:

由于在评论中提到,如果你使用了最新的骨干那么你可以做以下

As mentioned in the comments, if you use the latest backbone localStorage plugin then you can do the following

Backbone.sync = function Sync() {
    Backbone.ajaxSync.apply(this, arguments);
    return Backbone.localSync.apply(this, arguments);
};

这篇关于Backbone.js的能够做到的休息和localStorage的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 02:42