2013-03-15 32 views
0

所以,JStree打开所有的父节点负载

这里是一个源

<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,这里... https://github.com/vakata/jstree

干杯, T.

+0

你可以提供工作jsfiddle吗? – Radek 2013-03-18 00:11:11

回答

0

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

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

+0

这不起作用... data.rslt.obj未定义。从我所看到的新版本的jsTree以不同的方式包装对象。 – talfirevic 2013-03-15 12:18:12

0

不知道是否有帮助。但这里是我做的:

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

只需通过jsTree DOM元素和ID(449)的功能。