以前一直是用jsonstore加载远程数据,最近要做combox加载webservice返回的本地数据,进了误区弄了好久,不过把store研究了下,自己做个记录方便以后使用,也给遇到同样问题的同学做个参考
1.1:jsonstore加载远程数据:
var dictComboBox = new Ext.form.ComboBox({
fieldLabel:'证件类型',
id:'idNoType',
name:'dictType',
readOnly:false,
triggerAction:'all',
editable:false,
anchor:'90%',
emptyText:'请选择...',
store:new Ext.data.JsonStore({
url:this.basePath+'BasePackage/common_getSystemDictionaryItem?item_id=20003',
fields:["dictValue","dictValueDesc"],
root:'field1'
}),
valueField:'dictValue',
displayField:'dictValueDesc'
});
远程返回数据格式:json
{"field1":[{"dictValue":"","dictValueDesc",""},{"dictValue":"","dictValueDesc",""}]}
最好加上editable:false,否则可以自己输入,导致传的数据格式出问题
1.2:jsonstore加载本地数据
var cardComboBox = new Ext.form.ComboBox({
fieldLabel:'卡号',
id:'oldCard',
name:'dictType',
readOnly:false,
triggerAction:'all',
editable:false,
anchor:'90%',
mode:'local',
emptyText:'请选择...',
store:cardStore,
displayField:'card_no'
});
var cardStore = new Ext.data.JsonStore({
fields:['card_no'],
root:'field1'
});
Ext.Ajax.request({url:...,
params:{requesttype:"ajax"},
jsonData:jsonString,
callback:function (options, success, response) {
if (success) {
var jsonObj = Ext.util.JSON.decode(response.responseText);
if (jsonObj.result) {
var retField1 = jsonObj.field1;
if(retField1.length == 0){
...
return;
}else{
cardStore.loadData(jsonObj);
}
} else {
...
}
} else {
...
}
}});
ajax返回的json数据格式:
{"result":true,"field1":[{"card_no":""},{"card_no":""}]}
之前没怎么看过combobox,combobox默认的读取数据方式是远程读取,需要设url或proxy,没设会一直包proxy对象为空,mode:'local'将combobox设置为读取本地数据。