SSH combines with jquery to achieve a three level linkage effect

  • 2020-05-27 05:40:18
  • OfStack

In this paper, the example of jquery for you to share the implementation of the level 3 linkage of the specific code, for your reference, the specific content is as follows

jsp page section:


 <li id="floors">
    <span class="title" id="floorShow"> Building selection: </span>
    <select name="build" id="build" style="width: 282px;height: 40px;" onchange="floor2()">
    </select>
 </li>
 <li id="builds">
    <span class="title" id="floorShow"> Housing options: </span>
    <select name="builds" id="floot2" style="width: 282px;height: 40px;">
    </select>
</li>

js parts:


  function floor(){

    document.getElementById("build").options.length =0;
    document.getElementById("floot2").options.length =0;
    var parentId = document.getElementById("village").value;

    if(parentId == 0){

    }else{
      $.ajax({
        type : "post",
        url : "floor.action",
        data : {"parentId":parentId},
        dataType : "json",
        success :function(data){

          console.log(data);
          var len = data.length;

          var htm = "<option value='0'> Please select a </option>";
          for(var i=0;i<len;i++){
            htm += "<option value='"+data[i].id+"'>"+data[i].info+"</option>";
          }

          $("#build").append(htm);
        }
      })
    }
  }

  function floor2(){
    document.getElementById("floot2").options.length =0;
    var build = document.getElementById("build").value;

    if(build == 0){

    }else{
      $.ajax({
        type : "post",
        url : "floor2.action",
        data : {"parentId":build},
        dataType : "json",
        success : function(data){
          var len = data.length;
          var htm = "<option value='0'> Please select a </option>";
          for(var i=0;i<len;i++){
            htm += "<option value='"+data[i].id+"'>"+data[i].info+"</option>";
          }
          $("#floot2").append(htm);
        }
      })
    }
  }

struts2 configuration:


<package name="user" namespace="/" extends="json-default">
    <action name="floor" class="addressInfoAction" method="floor">
      <result type="json">
        <param name="root">floor</param>
      </result>
    </action>

    <action name="floor2" class="addressInfoAction" method="floor2">
      <result type="json">
        <param name="root">floor2</param>
      </result>
    </action>
  </package>

action parts:


public String floor(){
    System.out.println(" Here is the ajax call ");
    //floor = addressInfoService.getFloor(addressInfo.getParentId());
    System.out.println(addressInfo.getParentId());
    floor = addressInfoService.getFloor(addressInfo.getParentId());
    return SUCCESS;
  }

  public String floor2(){
    System.out.println(" Here is the ajax The first 2 Time to call ");
    System.out.println(addressInfo.getParentId());
    floor2 = addressInfoService.getBuild(addressInfo.getParentId());
    return SUCCESS;
  }

Finally, don't forget to import struts2-json-plugin-2.3.15.1. The version of the jar folder should also be identical to the version 1 of the other struts2 folder.


Related articles: