代码解释:当选则 guestCombo 里的值,级联查询出xieyiCombo 下拉框中的数据。
前端代码:
//--------------协议 start--------------
var xieyiRecord=[
{name : 'aid',type : 'string'},
{name : 'aname',type : 'string'}
];
var xieyiRecordHeads = Ext.data.Record.create(xieyiRecord);
var xieyiDatastore = new Ext.data.Store( {
proxy:new Ext.data.HttpProxy(new Ext.data.Connection({timeout:0,url:'/customize/control/getXieYi'})),
reader : new Ext.data.JsonReader( {
root : 'atype'
}, xieyiRecordHeads),
remoteSort : false
});
//xieyiDatastore.load();
var xieyiCombo = new Ext.form.ComboBox({
id:'xieyiCombo',
width:100,
forceSelection : true,
selectOnFocus: true,
triggerAction: 'all',
mode: 'local',
store: xieyiDatastore,
allowBlank: true,
valueField : 'aid',
displayField : 'aname',
value:'---请选择---'
});
//-------------- 协议 end --------------
var guestRecord=[
{name : 'aid',type : 'string'},
{name : 'aname',type : 'string'}
];
var guestRecordHeads = Ext.data.Record.create(guestRecord);
var guestDatastore = new Ext.data.Store( {
proxy:new Ext.data.HttpProxy(new Ext.data.Connection({timeout:0,url:'/customize/control/getGuest'})),
reader : new Ext.data.JsonReader( {
root : 'atype'
}, guestRecordHeads),
remoteSort : false
});
guestDatastore.load();
var guestCombo = new Ext.form.ComboBox({
id:'guestCombo',
width:100,
forceSelection : true,
selectOnFocus: true,
triggerAction: 'all',
mode: 'local',
store: guestDatastore,
allowBlank: true,
valueField : 'aid',
displayField : 'aname',
value:'---请选择---'
});
//添加select 监听事件,当选中下拉框中的值触发select函数
guestCombo.on('select',function(combo, records, eOpts){
var customerId = records.get('aid');
//var customerName = records.get('aname');
//alert(customerId+'-'+customerName);
xieyiCombo.reset();
xieyiDatastore.load({ params: { customerId: customerId} });
});
后端代码【java】:
public static String getGuest(HttpServletRequest request,HttpServletResponse response){
GenericDelegator delegator = (GenericDelegator)request.getAttribute("delegator");
List types = new ArrayList();
String sqlCommand = "select meta_customer_info_id,META_CUSTOMER_INFO from meta_customer_info WHERE STATE != 'DEL'";
SQLProcessor du = MyDelegatorUtil.getSQLProcessor(delegator);
ResultSet rs = null;
try {
rs = du.executeQuery(sqlCommand);
while(rs.next()){
Map map = new HashMap();
map.put("aid", rs.getString(1));
map.put("aname", rs.getString(2));
types.add(map);
}
} catch (GenericDataSourceException e) {
e.printStackTrace();
return "error";
} catch (GenericEntityException e) {
e.printStackTrace();
return "error";
} catch (SQLException e) {
e.printStackTrace();
return "error";
}finally{
MyDelegatorUtil.closeRS(rs);
MyDelegatorUtil.closeSQLProcessor(du);
}
Map jsonmap = new HashMap();
jsonmap.put("atype", types);
JSONObject jsb = JSONObject.fromMap(jsonmap);
writeStr(response, jsb);
return "success";
}
public static String getXieYi(HttpServletRequest request,HttpServletResponse response){
GenericDelegator delegator = (GenericDelegator)request.getAttribute("delegator");
String customerId = request.getParameter("customerId");
List types = new ArrayList();
String sqlCommand = "select META_CONTRACT_ID,META_CONTRACT from meta_contract WHERE META__CUSTOMER_AND_CONTRACT_ID = '"+customerId+"' and STATE != 'DEL'";
SQLProcessor du = MyDelegatorUtil.getSQLProcessor(delegator);
ResultSet rs = null;
try {
rs = du.executeQuery(sqlCommand);
while(rs.next()){
Map map = new HashMap();
map.put("aid", rs.getString(1));
map.put("aname", rs.getString(2));
types.add(map);
}
} catch (GenericDataSourceException e) {
e.printStackTrace();
return "error";
} catch (GenericEntityException e) {
e.printStackTrace();
return "error";
} catch (SQLException e) {
e.printStackTrace();
return "error";
}finally{
MyDelegatorUtil.closeRS(rs);
MyDelegatorUtil.closeSQLProcessor(du);
}
Map jsonmap = new HashMap();
jsonmap.put("atype", types);
JSONObject jsb = JSONObject.fromMap(jsonmap);
writeStr(response, jsb);
return "success";
}