我已经构建了一个破损的工作示例 here 。第一次加载页面时,默认值将加载到表单中。当您更改数据并刷新时,将显示上次更改的值。但是,在第一次页面查看(再次刷新)之后,不会保留进一步的更改,因为它看起来像一个名为 my-proxy-undefined
的值。正在设置而不是 my-proxy-1
正在更新。这是怎么回事?
型号:
Ext.regModel('MyModel', {
fields: [
{name: 'var1', type: 'integer'}
],
proxy: {
type: 'localstorage',
id: 'my-proxy'
}
});
商店:
var myStore = new Ext.data.Store({
model: 'MyModel',
listeners: {
load: function(store, records, successful) {
if (this.getCount() == 0) {
console.log("Count 0, loading defaults");
this.add(app.defaults.vars);
this.sync();
}
myForm.load(store.first());
}
},
autoLoad: true,
autoSave: true
});
更改表单上的监听器:
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'
}
});
由于可用性错误,您需要将 id 设置为字段。
关于javascript - ExtJS、SenchaTouch - LocalStorage 更新仅在首页加载时有效?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7479113/