easyui的下拉框動(dòng)態(tài)加載數(shù)據(jù),高校中要根據(jù)首先查詢所有學(xué)院,然后根據(jù)學(xué)院動(dòng)態(tài)加載課程。下面看如何實(shí)現(xiàn)。
網(wǎng)站建設(shè)哪家好,找成都創(chuàng)新互聯(lián)!專注于網(wǎng)頁設(shè)計(jì)、網(wǎng)站建設(shè)、微信開發(fā)、小程序設(shè)計(jì)、集團(tuán)企業(yè)網(wǎng)站建設(shè)等服務(wù)項(xiàng)目。為回饋新老客戶創(chuàng)新互聯(lián)還提供了若羌免費(fèi)建站歡迎大家使用!
1.界面效果
2. html + js代碼
<span>學(xué)院名稱:</span> <input class="easyui-combobox" id="collegeName"> <span>課程名稱:</span> <input class="easyui-combobox" id="courseName"><br/>
$(function() { // 下拉框選擇控件,下拉框的內(nèi)容是動(dòng)態(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',//自動(dòng)高度適合 valueField:'id', textField:'courseName' }); });
3.后臺(tái)代碼
@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") /** * 動(dòng)態(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格式后綁定到前臺(tái)控件上。
以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持創(chuàng)新互聯(lián)。
網(wǎng)站名稱:easyui下拉框動(dòng)態(tài)級(jí)聯(lián)加載的示例代碼
本文來源:http://chinadenli.net/article22/ppcpjc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站設(shè)計(jì)、定制開發(fā)、網(wǎng)站建設(shè)、Google、網(wǎng)站制作、網(wǎng)站收錄
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)