easyui的下拉框动态加载数据,高校中要根据首先查询所有学院,然后根据学院动态加载课程。下面看如何实现。
1.界面效果
2. html + js代码
内容是动态查询数据库信息
$('#collegeName').comboBox({
url:'${pageContext.request.contextPath}/loadInstitution',editable:false,//不可编辑状态
cache: false,panelHeight: '150',valueField:'id',textField:'institutionName',onHidePanel: function(){
$("#courseName").comboBox("setValue",'');//清空课程
var id = $('#collegeName').comboBox('getValue');
//alert(id);
$.ajax({
type: "POST",url: '${pageContext.request.contextPath}/loadCourse?id=' + id,cache: false,dataType : "json",success: function(data){
$("#courseName").combo<a href="/tag/Box/" target="_blank" class="keywords">Box</a>("loadData",data);
}
});
}
});
$('#courseName').comboBox({
//url:'itemManage!categorytbl',//不可编辑状态
cache: false,//自动高度适合
valueField:'id',textField:'courseName'
});
});
方法、类#成员]
* @deprecated
*/
public void loadInstitute(HttpServletRequest request,HttpServletResponse response) throws Exception {
try {
JackJsonUtils JackJsonUtils = new JackJsonUtils();
List institutionList = institutionBean
.queryAllColleage();
System.out.println("学院list大小=====" + institutionList.size());
String result = JackJsonUtils.BeanToJson(institutionList);
System.out.println(result);
JsonUtils.outJson(response,result);
} catch (Exception e) {
logger.error("加载学院失败",e);
}
}
@RequestMapping("/loadCourse")
/**
- 动态加载课程
- @param
- @param
- @return void
- @exception/throws [违例类型] [违例说明]
- @see [类、类#方法、类#成员]
- @deprecated
*/
public void loadCourse(HttpServletRequest request,HttpServletResponse response) throws Exception {
JackJsonUtils JackJsonUtils = new JackJsonUtils();
String id = request.getParameter("id");
System.out.println("学院id====" + id);
try {
if(id != null && id != ""){
ListlistCourseInfoList = courseBean
.queryAllCourseInfos(id);
System.out.println("课程list大小=====" + listCourseInfoList.size());
String result = JackJsonUtils.BeanToJson(listCourseInfoList);
System.out.println(result);
JsonUtils.outJson(response,result);
}
} catch (Exception e) {
logger.error("加载课程失败",e);
}
}