在用dtree,去看官网例子:http://destroydrop.com/javascripts/tree/,我想点击“My example tree”把整个目录都收起来,这个应该怎么修改呢?

解决方案 »

  1.   

    给他添加一个click事件,调用closeAllChildren方法,把他所有的子节点都关闭。
      

  2.   

    它的api里面也没有closeAllChildren这个方法啊!里面只有
    // Open/close all nodesdTree.prototype.openAll = function() { this.oAll(true);};dTree.prototype.closeAll = function() { this.oAll(false);};
    这两个方法也只能收缩My example tree的子节点的子节点,我现在是想收缩My example tree的子节点。
      

  3.   

    那你找到“My example tree”节点,然后调用这个closeAll方法即可
      

  4.   


    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不够新。下载个新版本
      

  5.   

    var t = new dTree();
    t.closeAllChildren(根节点对象);
      

  6.   

    <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>
    这样?d.closeAllChildren('所有的项目');不是这样哦
      

  7.   

    是对象,不是所有的项目
    d.closeAllChildren(document.getElementById("0"))
     d.add(0,-1,'所有的项目'); 0是当前node的id
      

  8.   

    还是有错误,我的代码如下:<div class="dtree">
    <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>
      

  9.   

    你误解了我的意思  我是想把项目1,项目2也收起来,当点击使用这个方法(d.closeAllChildren(d.root))的时候项目1,项目2要不显示出来。
      

  10.   

    <a href="javascript:d.closeAllChildren(d.aNodes[0])">我要关闭全部</a>
      

  11.   

    <a href="javascript:d.closeAll()">清空</a> 
      

  12.   

    js文件倒着看的!看到上面却出来个 closeall 晕!
    那个我也试了!我这里!可以
      

  13.   

    不是那个意思,closeAll我这里也可以,我现在是想把http://destroydrop.com/javascripts/tree/这里的Node1.2.3等等这些子菜单收起来,不显示出来。
      

  14.   

    function closeall(){
    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 好久没这么写了!不知道对不对!这方法你做参考吧!还有就是!你可以在根节点下只建一个子类啊!在这个子类下面分就是!你再操作这个子类不就行了!??
      

  15.   

    参考 dtree 里面的函数
    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';};
      

  16.   

    邮件已发出!请查收你的邮箱 [email protected]