ComboBox 的级联查询

代码解释:当选则 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";
	}

 

转载于:https://my.oschina.net/qimhkaiyuan/blog/1503000

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值