开发者

ExtJS, SenchaTouch - LocalStorage updates only work on first page load?

I've built a working example of the breakage here. The first time you load the page, the defaults are loaded into the form. When you change the data and refresh, the last-changed-value is present. However, after the first page view (refresh again), no further changes are persisted, as it looks like a value called my-proxy-undefined is getting set instead of my-proxy-1 getting updated. What's going on?

Model:

Ext.regModel('MyModel', {
    fields: [
        {name: 'var1', type: 'integer'}
    ],
    proxy: {
        type: 'localstorage',
        id: 'my-proxy'
    }
});

Store:

 var myStore = new Ext.data.Store({
                    model: 'MyModel',
                    listeners: {
                        load: function(store, records, successful) {
                            if (this.getCount() == 0) {
                                console.log("Count 0, loading defaults");
        开发者_JAVA技巧                        this.add(app.defaults.vars);
                                this.sync();
                            }

                            myForm.load(store.first());
                        }
                    },
                    autoLoad: true,
                    autoSave: true
                });

Change listeners on the form:

listeners:{
      change:function(el, newValue, oldValue) {
      var maxesRecord = myStore.first();
      maxesRecord.set(el.name, newValue);
      maxesRecord.save();
   }
}


Ext.regModel('Maxes', {
    fields: [
        {name: 'id', type: 'integer'},
        {name: 'var1', type: 'integer'}
    ],
    proxy: {
        type: 'localstorage',
        id: 'my-proxy'
    }
});

Because of a usability bug, you need to set the id as a field.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜