问题描述
|
我正在尝试使用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\"
});
[...]
谢谢!
解决方法
使用此Html5商店,您不必使用findAll方法。
Setup方法将预加载对象并实例化模型。
本文介绍了如何使用它:http://awardwinningfjords.com/2010/05/21/html5-localstorage-for-javascriptmvc.html
您也可以访问此待办事项列表以了解其他(且更简单)的会话存储解决方案:http://forum.javascriptmvc.com/topic/sexy-jmvc-todo-demo-nsfw