前段代码:
转诊医院 :
<select id="tohospital" name="tohospital" style="width: 214px" οnchange="getKishis();"> <option value ="">请选择</option> <#if (returnMap.hospitalsList?size > 0) > <#list returnMap.hospitalsList as hospitalsList> <option value ="${hospitalsList.name!}">${hospitalsList.name!}</option> </#list> </#if></select>
转诊科室: <select id="todepartment" name="todepartment" style="width: 214px"> <option value ="">请选择</option> </select>
//发送ajax实现科室下拉列表级联跟新 function getKishis(){ $.ajax({ url:"${request.contextPath}/findKeshis.action", type:"post", data:{hname:$("#tohospital").val()}, dataType:'json', success: function (jsonArray){ //1.清空科室下拉列表原有的option $("#todepartment").empty(); //2.更新科室下拉列表 for(var i=0;i<jsonArray.length;i++){ var jsonObj = jsonArray[i]; var $option =$("<option></option>"); $option.val(jsonObj.kname); $option.text(jsonObj.kname); $("#todepartment").append($option); } } }); }
后台代码:
//联级查询医院科室 public void findKeshis() throws IOException{ List<Keshis> keshis = keshisService.queryList(hname); //hibernate关联属性,解决json死循环 JsonConfig config = new JsonConfig(); config.setJsonPropertyFilter(new PropertyFilter() { @Override public boolean apply(Object arg0, String arg1, Object arg2) { if (arg1.equals("keshis")) { return true; } else { return false; } } }); JSONArray jsonData=JSONArray.fromObject(keshis,config); System.out.println(jsonData); HttpServletResponse response = ServletActionContext.getResponse(); response.setCharacterEncoding("utf-8"); response.getWriter().print(jsonData); }