1、靜態
[javascript] view plaincopy
var staticComboBox = new Ext.form.ComboBox({
fieldLabel:'回訪結果',
name:'result',
hiddenName:'result',
anchor:'100%',
editable:false,
readOnly:true,
mode:'local',
triggerAction:'all',
store:new Ext.data.SimpleStore({
fields:['code','desc'],
data:[
['全部','全部'],
['回訪成功','回訪成功'],
['無人','無人'],
['錯號','錯號'],
['停機','停機']
],
autoLoad:true
}),
value:'全部',
valueField:'code',
displayField:'desc'
});
2、動態:
[javascript] view plaincopy
//前台
var dynamicComboBox = new Ext.form.ComboBox({
fieldLabel:'回訪人員',
hiddenName:'operator',
name: 'operator',
mode: 'remote',
triggerAction:'all',
anchor:'100%',
editable : false,
readOnly:true,
store:
new Ext.data.Store({
proxy:new Ext.data.HttpProxy({
url:'TestAction!loadOperator.action'
}),
reader:new Ext.data.JsonReader({
root: 'root',
totalProperty: 'totalProperty',
fields:['code','desc']
}
),
autoLoad:true
}),
valueField: 'code', //值字段
displayField: 'desc', //顯示字段
value:'全部'
});
//后台參見:http://blog.csdn.net/xieshengjun2009/archive/2010/10/22/5959687.aspx
3、動態取值后 - 前台另添加一條記錄:
[javascript] view plaincopy
var record = Ext.data.Record.create([
{name:'code',type:'string',mapping:'0'},
{name:'desc',type:'string',mapping:'1'}
]);
var newRecord = new record({code:'全部',desc:'全部'});
var store = new Ext.data.Store({
proxy:new Ext.data.HttpProxy({url:'TestAction!loadGroupName.action'}),
reader:new Ext.data.JsonReader({
totalProperty:'results',
root:'rows',
fields:[
{name:'code'},
{name:'desc'}
]
}),
autoLoad:true,
listeners:{'load':function(){
store.add(newRecord);
}
}
});
var groupNameComboBox = new Ext.form.ComboBox({
name:'groupName',
width:130,
readOnly:true,
emptyText:'請選擇',
valueField:'code', //邏輯列名的實際值(code)
displayField:'desc', //邏輯列名的顯示值(decs)
triggerAction:'all',
editable : false,
width:140,
anchor:'100%',
store:store
4、動態取值后 - 后台另添加一條記錄:
前台:
[javascript] view plaincopy
var dynamicComboBox = new Ext.form.ComboBox({
fieldLabel:'回訪人員',
hiddenName:'operator',
name: 'operator',
mode: 'remote',
triggerAction:'all',
anchor:'100%',
editable : false,
readOnly:true,
store:
new Ext.data.Store({
proxy:new Ext.data.HttpProxy({
url:'TestAction!loadOperator.action'
}),
reader:new Ext.data.JsonReader({
root: 'root',
totalProperty: 'totalProperty',
fields:['code','desc']
}
),
autoLoad:true
}),
valueField: 'code', //值字段
displayField: 'desc', //顯示字段
value:'全部'
});
后台:
[java] view plaincopy
Opterator optr = new Opterator();//返回的列表對象(自定義)
List<Opterator> list = testService.loadtOpterator(map);
Iterator<Opterator> it = list.iterator();
int i=0;
//將list列表數據封裝成json格式的數據
JSONObject jsonObject = new JSONObject();
JSONArray jsonArray = new JSONArray();
JSONObject jsonAll = new JSONObject();
jsonAll.put("code", "全部");
jsonAll.put("desc", "全部");
jsonArray.put(i++, jsonAll);
while(it.hasNext()){
JSONObject jsonObj = new JSONObject();
optr = (Opterator)it.next();
jsonObj.put("code", sr.getOptr());
jsonObj.put("desc", sr.getOptr());
jsonArray.put(i++, jsonObj);
}
jsonObject.put("totalProperty", list.size());
jsonObject.put("root", jsonArray);
// 輸出到前台
outJsonString(jsonObject.toString());
第五種:直接在store的回掉函數里調用:
store.load({
callback: function(records, operation, success) {
store.insert(store.getCount()+1,[{'code':0,'desc':'全部'}])
},
scope: this
});
---------------------
作者:申公
來源:CSDN
原文:https://blog.csdn.net/haitaofeiyang/article/details/50204533?utm_source=copy
版權聲明:本文為博主原創文章,轉載請附上博文鏈接!