extjs,senchatouch- formpanel可以从商店中加载值吗?
如何将商店中的值加载到表单面板中?我在这里构建了一个整个损坏的示例。
我不确定为什么我的表单字段没有加载。
型号:
Ext.ns('app', 'app.defaults');
Ext.regModel('MyModel', {
fields: [
{name: 'var1', type: 'integer'}
]
});
app.defaults.vars = {
var1: 5
};
商店:
var myStore = new Ext.data.Store({
model: 'MyModel',
proxy: {
type: 'localstorage',
id: 'model-proxy'
},
listeners: {
load: function(store, records, successful) {
if (this.getCount() > 1) {
alert('Error: More than one record is impossible.');
this.proxy.clear();
}
if (this.getCount() == 0) {
alert( "Count 0, loading defaults");
this.add(app.defaults.vars);
this.sync();
}
console.log("Attempting to load store");
myForm.load(this);
}
},
autoLoad: true,
autoSave: true
});
形式:
var myForm = new Ext.form.FormPanel({
id: 'my-form',
scroll: 'vertical',
items: [
{
xtype: 'fieldset',
defaults: {
labelWidth: '35%'
},
items: [
{
xtype: 'numberfield',
id: 'var1',
name: 'var1',
label: 'Var1',
placeHolder: '100',
useClearIcon: true
}
]
}
]
});
How do you load values into a formpanel from a store? I've built an entire broken example here.
I'm not sure why my form fields aren't loaded.
The model:
Ext.ns('app', 'app.defaults');
Ext.regModel('MyModel', {
fields: [
{name: 'var1', type: 'integer'}
]
});
app.defaults.vars = {
var1: 5
};
The store:
var myStore = new Ext.data.Store({
model: 'MyModel',
proxy: {
type: 'localstorage',
id: 'model-proxy'
},
listeners: {
load: function(store, records, successful) {
if (this.getCount() > 1) {
alert('Error: More than one record is impossible.');
this.proxy.clear();
}
if (this.getCount() == 0) {
alert( "Count 0, loading defaults");
this.add(app.defaults.vars);
this.sync();
}
console.log("Attempting to load store");
myForm.load(this);
}
},
autoLoad: true,
autoSave: true
});
The form:
var myForm = new Ext.form.FormPanel({
id: 'my-form',
scroll: 'vertical',
items: [
{
xtype: 'fieldset',
defaults: {
labelWidth: '35%'
},
items: [
{
xtype: 'numberfield',
id: 'var1',
name: 'var1',
label: 'Var1',
placeHolder: '100',
useClearIcon: true
}
]
}
]
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我找到了将FormPanel与数据联系起来的其他方法
将表单加载后,按照代码加载插入后
,然后加载记录而不是商店。加载
记录[0]
而不是此
。I found other way to connect formpanel with the data
After the form is loaded insert following code
So, then, load a record instead of the store. Load
records[0]
instead ofthis
.