日期:2014-05-16  浏览次数:20463 次

求教jquery树形控件的问题
工程中用到了ssh 框架,
现在我在action里已经把属于顶级节点的所有子节点都获取到了,
如:
 
Java code

        /*
     * 树控件测试方法
     * @see com.opensymphony.xwork2.ActionSupport#execute()
     */
    public String execute() throws Exception {
                // 从数据库中查询出顶级节点的类。参数1 是指数据库表中序号为1,只有一个,代表父类。
        Party party =  partyService.findparty(1);
        Set<Party>partySet = new HashSet<Party>();
        Set<Party> set = partyService.findAllChildren(party, partySet);
        Map map = new HashMap();
                // 将set放入map中,好在页面显示。
        for (Party p: set) {
            map.put(p.getId(), p);
        }
        request.setAttribute("map",map);
        return "dtree";
    }
 

上面这个方法是查询出数据库中所有的属于顶级节点的方法。将其保存在map中,

  findAllChildren(party, partySet)方法:
 
Java code

  public Set<Party> findAllChildren(Party party, Set<Party> parties) {
        // 子节点中去除自己本身
        if (party.getChildren().contains(party)) {
            party.getChildren().remove(party);
        }
        parties.addAll(party.getChildren());

        // 如果有子部门,查询子部门的子部门

        if (party.getChildren().size() > 0) {

            for (Party child : party.getChildren()) {

                findAllChildren(child, parties);

            }

        }
        return parties;
    }

  


页面是这样获取显示的:

HTML code
 

<%@ page contentType="text/html; charset=UTF-8" %>
   
<%@ taglib prefix="s" uri="/struts-tags"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"> <%=basePath%>
<head>
<script src=" <%=basePath + "js/jquery/lib/jquery.js"%>" type="text/javascript"> </script>
<!-- 
<script src=" <%=basePath + "js/jquery/lib/jquery.cookie.js"%>" type="text/javascript"> </script> -->
<script src=" <%=basePath + "js/jquery/jquery.treeview.js"%>" type="text/javascript"> </script>
<script src=" <%=basePath + "js/jquery/lib/myjquery.js"%>" type="text/javascript"> </script>
<link rel="stylesheet" type="text/css" href=" <%=basePath + "js/jquery/jquery.treeview.css"%>">
<link rel="stylesheet" type="text/css" href=" <%=basePath + "js/jquery/screen.css"%>" >

<title>dtree </title>
</head>

<body>

  <div id="main">
  <ul id="browser" class="filetree">
  <span class="folder">
      flight
</span>


   
  <s:iterator value="#request.map.keySet()" id="id"> 
      <li>
      <s:if test="#request.map.get(#id).leaf == 1">
            <