Home > Article > Web Front-end > Dynamic cascading loading of ui drop-down box in easy
This article mainly introduces the sample code of dynamic cascade loading of easyui drop-down box. The editor thinks it is quite good. Now I will share it with you and give it as a reference. Let's follow the editor to take a look.
easyui's drop-down box dynamically loads data. In colleges and universities, all colleges must be queried first, and then courses are dynamically loaded according to the college. Let’s see how to achieve this.
1.Interface effect
##2. html js code<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.Backend code
@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); } }According to the basics The provided interface queries colleges and courses, converts them into json format and binds them to the front-end control. The above is what I compiled for everyone. I hope it will be helpful to everyone in the future. Related articles:
Using Electron to build React Webpack desktop applications (detailed tutorial)
How to achieve left and right in WeChat mini program Sliding
What are the special data types in JavaScript
How to use ajax to request server data in WeChat applet
The above is the detailed content of Dynamic cascading loading of ui drop-down box in easy. For more information, please follow other related articles on the PHP Chinese website!