在下面您将找到一个具有两个字段的 Ext.form.Panel。我在模型中选择了两个有数据的随机字段。它们没有以表单形式呈现。请注意,在此代码中我没有在 Extjs 框架中使用 MVC。 如何渲染这些字段?我已经粘贴了 store.data.toSource() 的相关输出,以表明我的商店中确实有数据,并且只有一条记录。要以稍大的分辨率查看图像,请右键单击它并在另一个选项卡中查看。
NOTE: .toSource() only works in Mozilla Firefox
我尝试在创建表单后执行此操作,但没有成功:
taskForm.getForm().loadRecord(store.getAt(0));
代码:
var taskForm = Ext.create('Ext.form.Panel', {
title: 'Task',
id: 'form1',
width: 600,
height: 200,
bodyPadding: 10,
renderTo: 'TaskEditForm',
store: store,
style: {
'position': 'fixed',
'top': '100px',
'left': '10px'
},
items: [{
xtype: 'label',
labelAlign: 'right',
name: 'project_id',
fieldLabel: 'Project ID',
width: 100
}, {
xtype: 'label',
labelAlign: 'right',
name: 'user_responsible',
fieldLabel: 'User',
width: 100
}],
buttons: [{
text: 'Save Task Detail',
handler: function (btn) {
alert(store.data.toSource());
}
}]
});
========
编辑:@Evan
此代码给出以下错误:
taskForm.getForm().loadRecord(store.getAt(0));
错误:
TypeError: record is undefined
...
return this.setValues(record.data); // ext-all-debug.js (line 109529)
109529行:
loadRecord: function(record) {
this._record = record;
return this.setValues(record.data);
},
最佳答案
你读过文档了吗? store.data
是一个包含一堆记录的 MixedCollection
。 load
方法的文档说:
A class which handles loading of data from a server into the Fields of an Ext.form.Basic.
你不能只输入随机参数并期望东西能够工作。
您可能想要的是:
form.getForm().loadRecord(store.getAt(0));//将第一条商店记录加载到表单中
关于json - Extjs 4 : Render store data into Ext. form.Panel不使用MVC框架,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16928617/