ExtJS, SenchaTouch – FormPanel can’t load values from a store?
如何将值从商店加载到表单面板中?我在这里构建了一个完整的示例。
我不确定为什么我的表单域没有加载。
型号:
1
2 3 4 5 6 7 8 9 |
Ext.ns(‘app’, ‘app.defaults’);
Ext.regModel(‘MyModel’, { fields: [ {name: ‘var1’, type: ‘integer’} ] }); app.defaults.vars = { var1: 5 }; |
店铺:
1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
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”); |
形式:
1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
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 } ] } ] }); |
- @Gregory Nozik:更新了模型。它在 1-page live 示例的源代码中。
我找到了其他方式将表单面板与数据连接起来
加载表单后插入以下代码
1
2 3 |
myForm.getForm().loadRecord(Ext.ModelManager.create({
‘var1’:5 }, ‘MyModel’)); |
那么,加载记录而不是存储。加载 records[0] 而不是 this.
- .load 或 .loadRecord 工作,只要您传入记录而不是存储。我将修复添加到您的答案中。
来源:https://www.codenong.com/7459361/