jsp页面
<td align="right"> 公路行政级别:</td>
<td align="left" > <input class="easyui-combobox" id="adminLevel" name="adminLevel" data-options="required:true,multiple:false,panelHeight:'auto'" /> </td>
<td align="right"> 路线编码:</td>
<td align="left" > <input class="easyui-combobox" id="roadNo" name="roadNo" data-options="required:true,multiple:false,panelHeight:'auto'" /> </td>
js代码
$(function() {
var _adminLevel = $('#adminLevel').combobox({
data :jsongl_xzjb,
method :'get',
editable: false,
valueField:'CODE',
textField:'CODETEXT',
onSelect: function (record) {
_zhbid.combobox({
disabled: false,
url: "BaseRoadSeg.ered?reqCode=selectRoadName&adminLevel=" + record.CODE,
valueField: 'roadNo',
textField: 'roadName'
}).combobox('clear');
}
});
var _zhbid = $('#roadNo').combobox({
disabled: true,
valueField: 'roadNo',
textField: 'roadName'
});
});
后台Java代码逻辑
public ActionForward selectRoadName(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
String adminLevel="";
if(G4Utils.isNotEmpty(request.getParameter("adminLevel"))){
//解决中文乱码
adminLevel = new String(request.getParameter("adminLevel").getBytes("GBK"), "utf-8");
}
List listLaws = g4Reader.queryForList("BaseRoad.getBaseRoadDtoByadminLevel", adminLevel);
String jsonString = JsonHelper.encodeObject2Json(listLaws);
write(jsonString, response);
return mapping.findForward(null);
}
sql语句
<select id="getBaseRoadDtoByadminLevel" parameterClass="string" resultClass="dto">
select roadNo,roadName from BASE_ROAD WHERE adminLevel=#adminLevel# and cancelFlag=0
</select>
返回的数据格式
[{
"roadNo":"1111",
"roadName":"111"},
{"roadNo":"453454",
"roadName":"5345"},
{"roadNo":"55345",
"roadName":"4534"
}]