這次給大家帶來easyui的下拉框動態級聯加載的實現方法(附代碼),easyui下拉框動態級聯加載的注意事項有哪些,下面就是實戰案例,一起來看一下。
easyui的下拉框動態加載數據,高校中要根據首先查詢所有學院,然后根據學院動態加載課程。下面看如何實現。
1.界面效果
2. html + js代碼
<span>學院名稱:</span> <input class="easyui-combobox" style="width:30%;" id="collegeName"> <span>課程名稱:</span> <input class="easyui-combobox" style="width:30%;" id="courseName"><br/>
$(function() { // 下拉框選擇控件,下拉框的內容是動態查詢數據庫信息 $('#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").combobox("loadData",data); } }); } }); $('#courseName').combobox({ //url:'itemManage!categorytbl', editable:false, //不可編輯狀態 cache: false, panelHeight: '150',//自動高度適合 valueField:'id', textField:'courseName' }); });
3.后臺代碼
@RequestMapping("/loadInstitution") /** * 加載學院 * @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("學院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 != ""){ 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); } }
根據基礎提供的接口查詢學院和課程,轉換為json格式后綁定到前臺控件上。
相信看了本文案例你已經掌握了方法,更多精彩請關注Gxl網其它相關文章!
推薦閱讀:
有哪些vue組件的書寫方法
通過JS獲取JSON數據并加載的步驟詳解
JS怎樣讓元素沿著拋物線軌跡運動
聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com