Home >Web Front-end >JS Tutorial >Dynamic cascading loading of ui drop-down box in easy

Dynamic cascading loading of ui drop-down box in easy

亚连
亚连Original
2018-06-23 15:46:281436browse

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() {    
   // 下拉框选择控件,下拉框的内容是动态查询数据库信息 
   $(&#39;#collegeName&#39;).combobox({  
       url:&#39;${pageContext.request.contextPath}/loadInstitution&#39;,  
       editable:false, //不可编辑状态 
       cache: false, 
       panelHeight: &#39;150&#39;, 
       valueField:&#39;id&#39;,   
       textField:&#39;institutionName&#39;, 
        
    onHidePanel: function(){ 
      $("#courseName").combobox("setValue",&#39;&#39;);//清空课程 
      var id = $(&#39;#collegeName&#39;).combobox(&#39;getValue&#39;);     
      //alert(id); 
       
     $.ajax({ 
      type: "POST", 
      url: &#39;${pageContext.request.contextPath}/loadCourse?id=&#39; + id, 
      cache: false, 
      dataType : "json", 
      success: function(data){ 
      $("#courseName").combobox("loadData",data); 
           } 
        });    
       } 
});   
    
   $(&#39;#courseName&#39;).combobox({  
     //url:&#39;itemManage!categorytbl&#39;,  
     editable:false, //不可编辑状态 
     cache: false, 
     panelHeight: &#39;150&#39;,//自动高度适合 
     valueField:&#39;id&#39;,   
     textField:&#39;courseName&#39; 
     }); 
    
});

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!

Statement:
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