jsonStore加載遠程和本地數據實例

 以前一直是用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設置爲讀取本地數據。
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章