• Ajax+json实现菜单动态级联


    1:jsp

    //级联ajax处理函数

     function areaChange(){
        var areano=document.all("areaNo").value;
        var url="${pageContext.request.contextPath}/infoAction.do?method=queryPeopleByPosition";
          $.post(url,{areaNo:areano,position:"200"},
            function(personList){ 
                  var personList=personList.personList; 
                  $("#businessManager").empty();//删除所有option选项
                  document.all("businessManager").options.add(new Option('-请选择-',''));
                  for(var p in personList){
                     document.all("businessManager").options.add(new Option(personList[p],personList[p]));
                  }               
            },"json");
        }

    <td>地区</td>
    <td>
           <html:select property="areaNo" style=" 80px" onchange="areaChange()">
                  <html:option value="">-请选择-</html:option>
                  <c:forEach items="${listArea }" var="i">
                   <html:option value="${i.nodeNo }">${i.nodeName }</html:option>
                  </c:forEach>
                 </html:select>
    </td>
    <td>业务经理</td>
    <td>
                 <html:select property="businessManager" styleId="businessManager" style=" 80px">
                  <html:option value="">-请选择-</html:option>
                  <c:forEach items="${teamList}" var="i">
                   <html:option value="${i.staffName }">${i.staffName }</html:option>
                  </c:forEach>
                 </html:select>
    </td>

    2、java处理方法

    //查询根据地区动态查询对应职级人员信息(动态级联使用)
     public ActionForward queryPeopleByPosition(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response)throws Exception{
      try {
       String areaNo=request.getParameter("areaNo");
       String position=request.getParameter("position");
       P2pStaffInfo queryParams = new StaffInfo();
          queryParams.setAreaNo(areaNo);// 地区
          queryParams.setPosition(position);//

          List<StaffInfo> personJavaList = infoLogic.queryStaffInfo(queryParams);

       JSONObject personList=new JSONObject();
       JSONObject person=new JSONObject();
       if (null!=personJavaList&&personJavaList.size()>0) {
        for (P2pStaffInfo po:personJavaList) {
         person.put(po.getStaffName(), po.getStaffName());
        }
       }
       personList.put("personList", person);
       response.setCharacterEncoding("gbk");
       PrintWriter pw=response.getWriter();
       pw.write(personList.toString());
       pw.flush();
       pw.close();
      } catch (Exception e) {
       log.error("根据职级动态级联地区查询出错!", e);
       e.printStackTrace();
      }
      return null;
     }

  • 相关阅读:
    Qt ‘/‘和‘\‘转化的方式
    Qt 快速转换路径(/斜杠与\反斜杠转换)
    Qt 网络编程:QNetworkAccessManager
    excel vba 单元格内部关键字突出显示改变颜色
    casbin 学习笔记【1】
    Linux
    AJAX
    Spring
    MyBatis
    Oracle查看表空间使用情况
  • 原文地址:https://www.cnblogs.com/Defry/p/4650704.html
Copyright © 2020-2023  润新知