2013-03-15 34 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)的功能。