easyui下拉框動態(tài)級聯(lián)加載的示例代碼
更新時間:2017年11月29日 16:37:08 作者:9_張曉
本篇文章主要介紹了easyui下拉框動態(tài)級聯(lián)加載的示例代碼,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
easyui的下拉框動態(tài)加載數(shù)據(jù),高校中要根據(jù)首先查詢所有學(xué)院,然后根據(jù)學(xué)院動態(tài)加載課程。下面看如何實現(xiàn)。
1.界面效果

2. html + js代碼
<span>學(xué)院名稱:</span> <input class="easyui-combobox" style="width:30%;" id="collegeName"> <span>課程名稱:</span> <input class="easyui-combobox" style="width:30%;" id="courseName"><br/>
$(function() {
// 下拉框選擇控件,下拉框的內(nèi)容是動態(tài)查詢數(shù)據(jù)庫信息
$('#collegeName').combobox({
url:'${pageContext.request.contextPath}/loadInstitution',
editable:false, //不可編輯狀態(tài)
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").combobox("loadData",data);
}
});
}
});
$('#courseName').combobox({
//url:'itemManage!categorytbl',
editable:false, //不可編輯狀態(tài)
cache: false,
panelHeight: '150',//自動高度適合
valueField:'id',
textField:'courseName'
});
});
3.后臺代碼
@RequestMapping("/loadInstitution")
/**
* 加載學(xué)院
* @param
* @param
* @return void
* @exception/throws [違例類型] [違例說明]
* @see [類、類#方法、類#成員]
* @deprecated
*/
public void loadInstitute(HttpServletRequest request,
HttpServletResponse response) throws Exception {
try {
JackJsonUtils JackJsonUtils = new JackJsonUtils();
List<Institution> institutionList = institutionBean
.queryAllColleage();
System.out.println("學(xué)院list大小=====" + institutionList.size());
String result = JackJsonUtils.BeanToJson(institutionList);
System.out.println(result);
JsonUtils.outJson(response, result);
} catch (Exception e) {
logger.error("加載學(xué)院失敗", e);
}
}
@RequestMapping("/loadCourse")
/**
* 動態(tài)加載課程
*
*
* @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("學(xué)院id====" + id);
try {
if(id != null && id != ""){
List<CourseInfo> listCourseInfoList = 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);
}
}
根據(jù)基礎(chǔ)提供的接口查詢學(xué)院和課程,轉(zhuǎn)換為json格式后綁定到前臺控件上。
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
jQuery插件form-validation-engine正則表達(dá)式操作示例
這篇文章主要介紹了jQuery插件form-validation-engine正則表達(dá)式操作,結(jié)合實例形式分析了jQuery插件form-validation-engine進(jìn)行正則驗證操作的相關(guān)技巧,需要的朋友可以參考下2017-02-02
jQuery中animate()的使用方法及解決$(”body“).animate({“scrollTop”:top})
這篇文章主要介紹了關(guān)于jQuery中animate()的使用方法及解決$("body").animate({"scrollTop":top})不被Firefox支持的問題,文中介紹的非常詳細(xì),相信對大家具有一定的參考價值,需要的朋友們下面來一起看看吧。2017-04-04

