モデルを明示的に更新するまで、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"
});
[...]
ありがとう!