【问题标题】:JStree open all parent nodes on loadJStree在加载时打开所有父节点
【发布时间】:2013-03-15 10:15:16
【问题描述】:

所以,

这是一个来源

 <ul>
  <li id="1">
    <a href="#">
      Product root
    </a>
    <ul>
      <li id="2">
        <a href="#">
          Electronicis
        </a>
        <ul>
          <li id="445">
            <a href="#">
              Computers
            </a>
            <ul>
              <li id="446">
                <a href="#">
                  SSD
                </a>
              </li>
            </ul>
            <ul>
              <li id="447">
                <a href="#">
                  GPU
                </a>
              </li>
            </ul>
            <ul>
              <li id="448">
                <a href="#">
                  MoBo
                </a>
              </li>
            </ul>
          </li>
        </ul>
        <ul>
          <li id="449">
            <a href="#">
              Navigation
            </a>
          </li>
        </ul>
      </li>
    </ul>
    <ul>
      <li id="3">
        <a href="#">
          Whatever
        </a>
      </li>
    </ul>
  </li>
</ul>

没有什么花哨的只是几个嵌套列表...

这是我的 jsTree 加载脚本

$("#jsTreeContainer")
            .jstree({
                "plugins": ["themes", "html_data", "ui" , "search"]
            })            
            .bind("select_node.jstree", function(event, data) {

                var selectedObj = data.selected;
                alert(selectedObj.attr("id"));

            })            
            .delegate("a", "click", function (event, data) { event.preventDefault(); });
    });

我现在想要完成的是,在页面加载时打开节点“导航”(id:449)。我试过 initally_open, initally_select 参数没有运气,我什至试过摆弄搜索插件,再次没有运气。

有没有人设法做到这一点,以及如何做到的?

这一定是一个非常常见的请求,但我找不到解决方案。

我正在使用来自 gitHub 的 master 分支,这里...https://github.com/vakata/jstree

干杯, T.

【问题讨论】:

  • 你能提供工作的jsfiddle吗?

标签: javascript jstree


【解决方案1】:

您可以尝试使用 $(treeid).jstree('open_node',id);

$("#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); 
  } 
});

查看更多详情 jsTree Open a branch

【讨论】:

  • 这不起作用... data.rslt.obj 未定义。据我所知,新版本的 jsTree 以不同的方式包装对象。
【解决方案2】:

不知道有没有帮助。但这是我所做的:

    function openNode(tree, nodeId) {
        $(tree).jstree("select_node", "#" + nodeId);
        $(tree).jstree("toggle_expand", "#" + nodeId);
    }

只需将 jsTree DOM 元素和 ID (449) 传递给函数。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多