下面的例子,试了一下,是可以成功的,
注意,需要吧默认值的id传过来 用setValue设置即可
还有,Store需要autoLoad : true, 否则combobox不自动load的时候就不能自动触发load的过程
fbf.DataForm = Ext.extend(Ext.form.FormPanel, {
baseCls : 'x-plain',
labelWidth : 40,
autoHeight : true,
initComponent : function($super) {
var data = this.data || {};
var cboType = new Ext.form.ComboBox({
fieldLabel : '类型',
anchor : '100%',
hiddenName : 'data.dataType.id',// 提交的名字
triggerAction : 'all', // 显示所有查询结果
mode : 'local',
store : new Ext.data.Store({
url : 'fbf/data-type!index.action',
autoLoad : true,
reader : new Ext.data.XmlReader({
record : 'DataType',
id : 'id'
}, ['id', 'type', 'state',
'description', 'remark',
'backup']),
listeners : {
load : function(store, records, options) {// 读取完数据后设定默认值
cboType.setValue(data.dataType);
}
}
}),
valueField : 'id',
displayField : 'type'
});
this.items = [new Ext.form.Hidden({
name : 'data.id',
value : data.id
}), cboType, new Ext.form.TextField({
fieldLabel : '数据',
anchor : '100%',
name : 'data.data',
value : data.data
}), new Ext.form.TextField({
fieldLabel : '状态',
anchor : '100%',
name : 'data.state',
value : data.state
}), new Ext.form.TextField({
fieldLabel : '说明',
anchor : '100%',
name : 'data.description',
value : data.description
}), new Ext.form.TextField({
fieldLabel : '备注',
anchor : '100%',
name : 'data.remark',
value : data.remark
}), new Ext.form.TextField({
fieldLabel : '备用',
anchor : '100%',
name : 'data.backup',
value : data.backup
})];
fbf.DataForm.superclass.initComponent.call(this);
}
});