combobox获取数据有两种方式:即参数mode的取值,local或者remote
我比较喜欢的数据格式是JSON,采用Ext.data.SimpleStore
1、mode:'local'
var departmentCode = [
['1','研发部'],['2','人事处'],['3','总经办']
];
new Ext.form.ComboBox({
fieldLabel: 'Department Code',
name:'departmentCode',
forceSelection: true,
listWidth: 200,
store: new Ext.data.SimpleStore(...{
fields: ['value', 'text'],
data : departmentCode
}),
valueField:'value',
displayField:'text',
typeAhead: true,
mode: 'local',
triggerAction: 'all',
selectOnFocus:true,
allowBlank:false
})
2、mode:'remote'
var combo = new Ext.data.JsonStore({
url:'url',
fields: ['departmentId','departmentname']});
combo.load();
new Ext.form.ComboBox({
fieldLabel: 'Department',
name:'department',
forceSelection: true,
listWidth: 150,
store: combo,
valueField:'departmentId',
displayField:'departmentname',
typeAhead: true,
mode: 'local',
triggerAction: 'all',
selectOnFocus:true,
allowBlank:false
})
其中json的格式如:{['1','研发部'],['2','财务处']}
注意:如果返回的json数据有多列,需要在new Ext.data.JsonStore的时候,在fields一项中填写所有column的名字,否则不能填充combobox
我比较喜欢的数据格式是JSON,采用Ext.data.SimpleStore
1、mode:'local'
var departmentCode = [
['1','研发部'],['2','人事处'],['3','总经办']
];
new Ext.form.ComboBox({
fieldLabel: 'Department Code',
name:'departmentCode',
forceSelection: true,
listWidth: 200,
store: new Ext.data.SimpleStore(...{
fields: ['value', 'text'],
data : departmentCode
}),
valueField:'value',
displayField:'text',
typeAhead: true,
mode: 'local',
triggerAction: 'all',
selectOnFocus:true,
allowBlank:false
})
2、mode:'remote'
var combo = new Ext.data.JsonStore({
url:'url',
fields: ['departmentId','departmentname']});
combo.load();
new Ext.form.ComboBox({
fieldLabel: 'Department',
name:'department',
forceSelection: true,
listWidth: 150,
store: combo,
valueField:'departmentId',
displayField:'departmentname',
typeAhead: true,
mode: 'local',
triggerAction: 'all',
selectOnFocus:true,
allowBlank:false
})
其中json的格式如:{['1','研发部'],['2','财务处']}
注意:如果返回的json数据有多列,需要在new Ext.data.JsonStore的时候,在fields一项中填写所有column的名字,否则不能填充combobox