Dynamic cascading loading of ui drop-down box in easy

亚连
Release: 2018-06-23 15:46:28
Original
1350 people have browsed it

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

学院名称:  课程名称: 
Copy after login
$(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' }); });
Copy after login

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 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 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); } }
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!