22

JQueryプラグインjsTree、http: //www.jstree.com/を使用し ています。次の方法でツリー全体を展開できます。

$("#tree").jstree("open_all");

また、特定のノード:

$("#tree").jstree("open_node", $('#childNode'));

ツリーのブランチを開くのに問題があります。ブランチを開くと正常に開きますが、親がある場合は開きません。

誰かがjsTreeでこれを成功させましたか?さらに情報が必要な場合はお知らせください。

ありがとう

Eef

4

8 に答える 8

19

オープンブランチのコードは正しいです。

例えば。ツリーのソース:

    <div id="treeTask">
       <ul>
          <li id="node_37"><a href="#">TEST1</a>
              <ul>
                  <li id="node_38"><a href="#">TEST2</a></li>
                  <li id="node_39"><a href="#">TEST3</a></li>
              </ul>
          </li>
      </ul>
   </div>

オープンノード:

$("#treeTask").jstree("open_node", $("#node_38"));
于 2010-11-13T07:25:52.363 に答える
10

このコードを試して、n番目のレベルまでノードを開きます

$("#myTree").jstree({options}).bind('loaded.jstree', function (e, data) {
    /** 
     * Open nodes on load (until x'th level) 
     */
    var depth = 3;
    data.inst.get_container().find('li').each(function (i) {
        if (data.inst.get_path($(this)).length <= depth) {
            data.inst.open_node($(this));
        }
    });
});
于 2013-03-18T19:58:49.187 に答える
9

バインディングを使用できます

$("#tree").bind("open_node.jstree", function (event, data) { 
  if((data.inst._get_parent(data.rslt.obj)).length) { 
    data.inst._get_parent(data.rslt.obj).open_node(this, false); 
  } 
}); 
于 2010-11-16T14:28:45.693 に答える
4

これは、特定のノードとそのすべての親を開くことができる関数です。

function expandNode(nodeID) {
    // Expand all nodes up to the root (the id of the root returns as '#')
    while (nodeID != '#') {
        // Open this node
        $("#jstree").jstree("open_node", nodeID)
        // Get the jstree object for this node
        var thisNode = $("#jstree").jstree("get_node", nodeID);
        // Get the id of the parent of this node
        nodeID = $("#jstree").jstree("get_parent", thisNode);
    }
}
于 2014-02-05T20:19:49.653 に答える
3

Tedのコードが機能していることがわかりましたが、少し変更する必要がありました。

 $('#jsTree').bind("open_node.jstree", function (event, data) { 
      if((data.inst._get_parent(data.rslt.obj)).length) { 
        data.inst.open_node(data.inst._get_parent(data.rslt.obj), false,true); 
      } 
    });
于 2011-01-11T11:40:50.120 に答える
3

jsonを使用する場合はこれを使用してください

$("#treeId").on
('loaded.jstree', function() {
 $("#treeId").jstree("open_node", $("#nodeId"));
 });
于 2018-01-18T11:22:15.847 に答える
2

以前のどれも私のために働いていなかったので、私はこのコードを作成しました、そしてそれは魅力のように働きます:)

$('#tree').on('open_node.jstree', function (event, data) { 
    if(data.node.parent !== "#") { 
        data.instance.open_node(data.node.parent); 
    } 
});
于 2017-03-22T15:51:41.423 に答える
0
    // Expand pasted, dragged and dropped node for jstree 3.3.1
        var objtree = $('#jstree');
        objtree.bind('paste.jstree', function(e, d) { objtree.jstree('open_all', '#' + d.parent); });
        $(document).bind('dnd_move.vakata', function(e, d) { objtree.jstree('open_all', $(d.event.target).closest('.jstree-node').attr('id')); });
        $(document).bind('dnd_stop.vakata', function(e, d) { objtree.jstree('open_all', $(d.event.target).closest('.jstree-node').attr('id')); });
于 2016-07-17T10:23:51.443 に答える