在用dtree,去看官网例子:http://destroydrop.com/javascripts/tree/,我想点击“My example tree”把整个目录都收起来,这个应该怎么修改呢?
解决方案 »
- 求能在IE9+版本(非兼容模式)和火狐下能用的一句脚本改编
- 百度地图API InfoWindow不会打开的问题
- extjs4.1中用ajax方式返回treepanel的store数据后一直显示加载状态,求帮助!!
- 想从网页中直接打开本地文件夹或网络文件夹并定位到指定文件
- 求解 js出现 WebCalendar.iframe.tableWeek is undefined ,在线等解决~@
- 如何实现突出光标所在的列?
- 急求textarea里用正则表达式替换回车符成段落的问题
- 如何过滤表单中的按钮
- 求助:在IE6.0,SP1中,怎么去掉IE标题栏同时控制IE大小。
- 用showModelessDialog() 打开窗口时,当打开它的窗口的URL改变时或者刷新,它会自动关闭,有没有办法使他不关闭呢?
- javascript innerHTML 图片的问题
- 我想在以下框架加收缩和展开效果 该怎么 请指教 多谢多谢
// Open/close all nodesdTree.prototype.openAll = function() { this.oAll(true);};dTree.prototype.closeAll = function() { this.oAll(false);};
这两个方法也只能收缩My example tree的子节点的子节点,我现在是想收缩My example tree的子节点。
dTree.prototype.closeLevel = function(node) { for (var n=0; n<this.aNodes.length; n++) { if (this.aNodes[n].pid == node.pid && this.aNodes[n].id != node.id && this.aNodes[n]._hc) { this.nodeStatus(false, n, this.aNodes[n]._ls); this.aNodes[n]._io = false; this.closeAllChildren(this.aNodes[n]); } }}// Closes all children of a nodedTree.prototype.closeAllChildren = function(node) { for (var n=0; n<this.aNodes.length; n++) { if (this.aNodes[n].pid == node.id && this.aNodes[n]._hc) { if (this.aNodes[n]._io) this.nodeStatus(false, n, this.aNodes[n]._ls); this.aNodes[n]._io = false; this.closeAllChildren(this.aNodes[n]); } }}
这2个方法够用了,可能是你的dtree不够新。下载个新版本
t.closeAllChildren(根节点对象);
<!-- d = new dTree('d'); d.add(0,-1,'所有的项目');
d.add(1,0,'项目1','example01.html');
d.add(2,1,'阶段1','example01.html');
d.add(3,2,'阶段1.1','example01.html');
d.add(4,1,'阶段2','example01.html');
d.add(5,4,'阶段2.2','example01.html');
d.add(6,0,'项目2','example01.html');
d.add(7,6,'阶段1','example01.html');
d.add(8,7,'阶段1.1','example01.html');
d.add(9,6,'阶段2','example01.html');
d.add(10,9,'阶段2.2','example01.html');;
document.write(d); //-->
</script>
这样?d.closeAllChildren('所有的项目');不是这样哦
d.closeAllChildren(document.getElementById("0"))
d.add(0,-1,'所有的项目'); 0是当前node的id
<a href="javascript:d.closeAllChildren(document.getElementById('0'));">closeAll</a> <script type="text/javascript">
<!-- d = new dTree('d'); d.add(0,-1,'所有的项目');
d.add(1,0,'项目1','example01.html');
d.add(2,1,'阶段1','example01.html');
d.add(3,2,'阶段1.1','example01.html');
d.add(4,1,'阶段2','example01.html');
d.add(5,4,'阶段2.2','example01.html');
d.add(6,0,'项目2','example01.html');
d.add(7,6,'阶段1','example01.html');
d.add(8,7,'阶段1.1','example01.html');
d.add(9,6,'阶段2','example01.html');
d.add(10,9,'阶段2.2','example01.html');;
document.write(d); //-->
</script></div>
那个我也试了!我这里!可以
for (var n=0; n<d.aNodes.length; n++) {
$("#dd"+n).hide();
} }dtree 是 多个div! 每一项的div的id 命名 是 d+ 树名 +序列。
这里你定义 d = new dTree('d'); 则 每项的id就是 dd+序列。这样我只能做个函数隐藏tree下面的所有div来实现你的需求!
上面例子我用的jquery 不知道你能看懂不!
function closeall(){
for (var n=0; n<d.aNodes.length; n++) {
eDiv=document.getElementById('dd'+n);
eDiv.style.display='none';
}
}
用jq 好久没这么写了!不知道对不对!这方法你做参考吧!还有就是!你可以在根节点下只建一个子类啊!在这个子类下面分就是!你再操作这个子类不就行了!??
dTree.prototype.nodeStatus = function(status, id, bottom) { eDiv = document.getElementById('d' + this.obj + id); eJoin = document.getElementById('j' + this.obj + id); if (this.config.useIcons) { eIcon = document.getElementById('i' + this.obj + id); eIcon.src = (status) ? this.aNodes[id].iconOpen : this.aNodes[id].icon; } eJoin.src = (this.config.useLines)? ((status)?((bottom)?this.icon.minusBottom:this.icon.minus):((bottom)?this.icon.plusBottom:this.icon.plus)): ((status)?this.icon.nlMinus:this.icon.nlPlus); eDiv.style.display = (status) ? 'block': 'none';};