<script type="text/javascript">
<!-- d = new dTree('d'); d.add(0,-1,'My example tree');
d.add(1,0,'Node 1','example01.html');
d.add(2,0,'Node 2','example01.html');
d.add(3,1,'Node 1.1','example01.html');
d.add(4,0,'Node 3','example01.html');
d.add(5,3,'Node 1.1.1','example01.html');
d.add(6,5,'Node 1.1.1.1','example01.html');
d.add(7,0,'Node 4','example01.html');
d.add(8,1,'Node 1.2','example01.html');
d.add(9,0,'My Pictures','example01.html','Pictures I\'ve taken over the years','','','img/imgfolder.gif');
d.add(10,9,'The trip to Iceland','example01.html','Pictures of Gullfoss and Geysir');
d.add(11,9,'Mom\'s birthday','example01.html');
d.add(12,0,'Recycle Bin','example01.html','','','img/trash.gif'); document.write(d); //-->
</script>就这个代码  我怎么用java来填充js里面的数据,我想做一个jsp动态的树状菜单!希望高手帮忙,谢谢!

解决方案 »

  1.   

    这个是哪个Dtree实现的吧.
    用jsp实现动态的效果,你可以建一张表,表的结构跟dtree.add(.....)里面的参数列表差不多.根据你的需要而建这张表吧.
    然后呢,在后台取出表的数据保存在容器里面,在jsp页面就可以foreach出来了.
    例如:<script language="javascript">
    d = new dTree("d");
    d.add("ROOT_MENU","-1","测试DTree","");
     <c:forEach items="${rights}" var="right">
    d.add('${right.code}','${right.parentCode}','${right.text}','${right.url}');
    </c:forEach>
    document.write(d);
    </script>
      

  2.   

    add 的前两个参数必须是数字形的吗  我现在有一个子父类别表 里面有6000多种分类 我要是再建表是不是太麻烦了
      

  3.   

    add里面的参数,数字,字符串都可以!你看他那个dtree.js的源码就知道了.如果你已经有表了,那你就从你的表读取出来,设置进去就好啦!
      

  4.   

    <script type="text/javascript">
    <!--
    d = new dTree('d');
    <%  while(rs.next()){ 
     String a1=rs.getString(1);
     String a2=rs.getString(2);
      String a3=rs.getString(3);
       String a4=rs.getString(4);
       System.out.print("--1:"+a1+"--2:"+a2+"--3:"+a3+"--4:"+a4+" <br/> ");
      %>
    d.add('<%=a1%>','<%=a2%>','<%=a4%>');
    <%}rs.close(); %>
    document.write(d);
    //-->
    </script>
    我用jsp这样写也不可以呀   a1、a2、a3、a4都是字符型a1是编码  a2是父级编码  a3是编号  a4是类别名看我这样写对吗?