<link rel="stylesheet" href="../jquery.treeview.css" />
<script src="../lib/jquery.js" type="text/javascript"></script>
<script src="../lib/jquery.cookie.js" type="text/javascript"></script>
<script src="../jquery.treeview.js" type="text/javascript"></script>
$("#tree").treeview({
/*
* 设置为True:所有的文件枝是关闭状态,
* 设置为False(默认):所有文件枝是打开的状态
*/
collapsed: true,
// 设置关闭打开速度
//animated: "medium",
animated:"fast",
/* 放置treecontrol的容器的id,treecontrol就是通过一个点击按钮可以展开,合并以及切换分支。*/
control:"#sidetreecontrol",
unique: true, /*设置为True:一个层次上只允许一个分支是打开的,设置为False(默认):一个层次上可以同时打开多个分支*/
//persist: "cookie", /*参数可选为cookie或location,设为cookie可以保存状态到cookie*/
persist: "location"
//cookieId: "treeview-black" /*cookie记录的名称,persist参数为cookie时才有效,*/
});
<ul id="tree">
<li class="expandable"><div class="hitarea expandable-hitarea"></div>注册登录(0)
<ul style="display: none;">
<li><a href="/officalquest/searchquest.do?kid=388">拥有账号</a>(0)</li>
<li><a href="/officalquest/searchquest.do?kid=389">获取密码</a>(0)</li>
<li class="expandable lastExpandable"><div class="hitarea expandable-hitarea"></div>如何登陆(0)
<ul style="display: none;">
<li class="last"><a href="/officalquest/searchquest.do?kid=391">你猜</a>(0)</li>
</ul>
</li>
</ul>
</li>
</ul>
问题描述:
(1) 多处使用时,如果你在一个树打开子树,去别一个树看,子树也是打开的。
原因:这个值一定是保存在cookie里面了,然后这两个菜单,共享了一个cookie数组。
解决办法:
$("#tree").treeview({
animated: "fast", /*资料有限,只查到一个参数,用于设置展开或关闭的速度*/
persist: "cookie", /*参数可选为cookie或location,设为cookie可以保存状态到cookie*/
collapsed: true, /*设置为True:所有的文件枝是关闭状态,设置为False(默认):所有文件枝是打开的状态*/
unique: true, /*设置为True:一个层次上只允许一个分支是打开的,设置为False(默认):一个层次上可以同时打开多个分支*/
control: "#sidetreecontrol", /* 放置treecontrol的容器的id,treecontrol就是通过一个点击按钮可以展开,合并以及切换分支。*/
cookieId: "treeview-black" /*cookie记录的名称,persist参数为cookie时才有效,*/
});
cookieId是解决上面遇到问题的所在,因为没有设置cookieId,值保持到了默认参数里。
(2) 当节点超过1000时,在IE 6下生成树表现的相当的慢,用户会明显地感知到合并的效果,体验极其不友好。
建议: 用firefox查找 树渲染后的效果,用定时调度的办法,定时去生成 树,然后这种合并的效果用户基本上是感知不到的。
总结:这种办法是可以解决 很多结点树展示的问题的。