簡單談談PHP vs Node.js
805
2023-12-08
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格式后綁定到前臺控件上。
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持綠夏網。
#免責聲明#
本站[綠夏技術導航]提供的一切軟件、教程和內容信息僅限用于學習和研究目的;不得將上述內容用于商業或者非法用途,否則,一切后果請用戶自負。本站信息來自網絡收集整理,版權爭議與本站無關。您必須在下載后的24個小時之內,從您的電腦或手機中徹底刪除上述內容。如果您喜歡該程序或內容,請支持正版,購買注冊,得到更好的正版服務。我們非常重視版權問題,如有侵權請郵件[admin@lxwl520.com]與我們聯系進行刪除處理。敬請諒解!