我正在尝试使用 JMVC 的localStorage 插件来缓存我的模型,直到我明确更新它们。
我发现的唯一示例如下,它表示我必须手动将模型存储在本地商店中。
function updateModel(params) {
MyModel.store.destroy(params.id);
MyModel.store.create(params);
}
我不确定如何将该示例应用于 JMVC 的常规模型方法。例如,在执行 ajax 调用之前,如何更新此模型的 findAll() 以在本地存储中查找模型?
$.Model.extend('MyCachedModel',
{
setup: function(){
this.storeType = SS.Model.HTML5Store.Local;
this._super.apply(this, arguments);
}
findAll: function( params, success, error ){
// How do I update this to store and retrieve models from localStorage?
$.ajax({
url: '/todo',
type: 'get',
dataType: 'json',
data: params,
success: this.callback(['wrapMany',success]),
error: error,
fixture: "//app/fixtures/todos.json.get"
});
[...]
谢谢!