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

Jquery.dynatree.js控件的使用

1,在后台拼字符串产生json,json的格式为:[{title :"xxxx",  key: xerx, ,expand:true/false ,children:[{title:"yyyyy",key:eeee,expand:true},

{title:"zzzzz",key:dfds,expand:true}]}]。这么嵌套下去,实际使用时可以用StringBuffer这样拼字符的速度快些。expand:true时产生的树是展开的,当为false时树是闭合的。把这个json字符串放入map中在前台展示。(我用的springmvc框架)

2,引入css和js文件:dynatree/src/skin/ui.dynatree.css,dynatree/jquery/jquery-ui.custom.js,dynatree/jquery/jquery.cookie.js,

dynatree/src/jquery.dynatree.js。

3,在jsp中添加这样的div      <div name=test  style="width:170px;height:200px;overflow: auto ;background-color: white; border: #83BCF5 1px solid;" value="1">

4,在js中:

$(function(){   //这是为了在打开页面时就调用这个方法
        initTree();
         });

function initTree(){
         //初始化树状结构
        $("#test").dynatree({
            checkbox: true,