能够用javascript的数组做为数据源,也能够用json做为数据源:javascript
1.用javascript数组java
var CountryCode = [
['93','Afghanistan(93)'],
['355','Albania (355)'],
['213','Algeria (213)'],
['684','American Samoa (684)'],
['376','Andorra (376)'],
['244','Angola (244)'],
.....
]
new Ext.form.ComboBox(...{
fieldLabel: 'Country Code',
name:'country_code',
forceSelection: true,
listWidth: 200,
store: new Ext.data.SimpleStore(...{
fields: ['value', 'text'],
data : CountryCode
}),
valueField:'value',
displayField:'text',
typeAhead: true,
mode: 'local',
triggerAction: 'all',
selectOnFocus:true,//用户不能本身输入,只能选择列表中有的记录
allowBlank:false
})json
2:用json做为数据源数组
var comboOptions = new Ext.data.JsonStore(...{
url:'myurl',
fields: ['id','name']});
comboOptions.load();
new Ext.form.ComboBox(...{
fieldLabel: 'Management Level',
name:'group_id',
forceSelection: true,
listWidth: 150,
store: comboOptions,
valueField:'id',
displayField:'name',
typeAhead: true,
mode: 'local',
triggerAction: 'all',
selectOnFocus:true,
allowBlank:false
})
this
myurl输出的json数据格式以下:url
[{"id":"1","name":"Super Admin"},{"id":"2","name":"Admin"}]spa
须要注意的是,若是返回的json数据有多列,须要在new JsonStore的时候,在fields一项中填写全部column的名字,不然不能填充combobox.net
第一种方式(这种方式,我在使用时,若是数据不是从后台传过来的就能够,若是是从后台传过来的就不行了,要使用第二种方式)、 var CountryCode = [ ['93','Afghanistan(93)'], ['355','Albania (355)'], ['213','Algeria (213)'], ['684','American Samoa (684)'], ['376','Andorra (376)'], ['244','Angola (244)'] ] var checkupperson = new Ext.form.ComboBox({ fieldLabel: '审核人', name:'checkupperson', forceSelection: true, listWidth: 200, store: new Ext.data.SimpleStore({ fields: ['value', 'text'], data : CountryCode }), valueField:'value', displayField:'text', typeAhead: true, mode: 'local', triggerAction: 'all', selectOnFocus:true,//用户不能本身输入,只能选择列表中有的记录 allowBlank:false, listeners:{ select:function(){ alert(this.value); } } }); checkupperson.on('beforerender',function(){ this.value=376; }); 第二种方式: var depCombo = new Ext.form.ComboBox({ fieldLabel:'部门', allowBlank: false, allowNegative: false, triggerAction: 'all', displayField :'depName', valueField :'depId', id:'test', store: new Ext.data.JsonStore({ fields: ['depId','depName'], url: '../combobox.do?action=getDepartmentComboBox', autoLoad : true, listeners :{ load:function(){ Ext.getCmp('test').setValue(17); } } //在此加一个这个玩意,就能够了,呵呵,是在jsonstore中加的,注意 }), editable :false });
第三种方式: