zoukankan      html  css  js  c++  java
  • 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;
     }

  • 相关阅读:
    Java B/S开发模式漫谈 (转)
    struts 使用多个配置文件 strutsconfig.xml
    java 验证邮箱格式正确性、验证字符串是否为数字
    Java获取各种常用时间方法
    创建HttpServlet的基本步骤
    struts1.x 配置文件之——web.xml详解
    最常用的JAVA包
    字符串转换为日期时间格式
    struts1.x 配置文件详解
    看看别人的博客,经验总结,很宝贵
  • 原文地址:https://www.cnblogs.com/Defry/p/4650704.html
Copyright © 2011-2022 走看看