2011-05-05 20 views
6

打開雙/單點擊/關閉的節點我怎麼能雙或單的節點名稱點擊打開/關閉節點?不管你喜歡在這裏工作the first tree sample - 但使用jsTree 0.9.8如何jsTree

-

<html> 
<head> 
<title> dashboard</title> 

<script type="text/javascript" src="_lib/jquery.js"></script> 
<script type="text/javascript" src="jquery.jstree.js"></script> 
<script type="text/javascript" src="_lib/jstreegrid.js"></script> 
<script type="text/javascript"> 
//<![CDATA[ 

$(document).ready(function(){ 

var data = [{ 
     data: "basics", 
     attr: {SOF: "<a href=\"http://www.w3schools.com\">Visit W3Schools.com!</a>"}, 
     children: [ 
     {data: "login", attr: {run: "run"}, 
      children: [     
      {data: "login", attr: {}} 
      ] 
     } , 
     {data: "Academic Year", attr: {run: "run"}, 
      children: [     
      {data: "login", attr: {}}, 
      {data: "Academic Year", attr: {filter: "mini", SOF: "<a href=\"http://www.w3schools.com\">Visit W3Schools.com!</a>"}} 
      ] 

     } 
     ] 
     }]; 
$("div#jstree").jstree({ 
plugins: ["themes","json_data","grid","dnd"], 
json_data: {data: data}, 
grid: { 
     columns: [ 
      {width: 220, header: "Group"}, 
         {cellClass: "col2", value: "run", width: 40, header: "run"}, 
         {cellClass: "col3", value: "filter", width: 40, header: "filter"}, 
         {cellClass: "col4", value: "SOF", width: 450, header: "SOF"} 
       ] 
      }, 
dnd: { 
drop_finish : function() { 
}, 
drag_finish : function() { 
}, 
drag_check : function (data) { 
return { 
after : true, 
before : true, 
inside : true 
}; 
} 
} 
}); 
}); 
//]]> 
</script> 
</head> 
<body> 
<div id="jstree"></div> 

</body> 
</html> 
+0

你想切換呢?能見度?其他一些風格? – 2011-05-05 01:30:32

+0

我的意思是打開/關閉節點 – Radek 2011-05-05 01:34:01

回答

11

一種方法是使類型和UI插件,並使用默認類型定義select_node事件處理程序,像這樣:

$(element) 
     .jstree({ 
      "types" : { 
       "types" : { 
        "default" : { 
         "select_node" : function(e) { 
              this.toggle_node(e); 
              return false; 
             } 

        } 
       } 
      }, 
      "plugins" : [ "themes", "html_data","types", "ui" ] }); 
+0

你能告訴我在我的代碼中,我需要插入你的代碼嗎? – Radek 2011-05-05 04:05:07

+1

將「類型」塊放在「插件」之前。不要忘記逗號!不要忘記在「插件」列表中添加「ui」和「類型」。 – 2011-05-05 04:08:18

+1

如果您是jsTree的新手,想要查找基本示例,請查看我的博客文章http://tkgospodinov.com/jstree-part-1-introduction/。希望有所幫助。 – 2011-05-05 04:11:31

1

不要你必須創建樹時添加clickable: [...]選項?

+0

我不知道:-)我在哪裏可以找到.... – Radek 2011-05-05 03:43:49

2

除了來自傳統知識的正確答案...

這解決方案將在您點擊帶有href屬性的樹項目(由JSON,XML數據或直接在HTML中設置)時破壞導航。

爲了解決這個問題,在葉配置的「類型」(其中錨必須觸發導航)設置此處理程序:

"select_node": function (e) { 
    document.location = e.children("a").attr("href"); 
    return false; 
} 
0
$('#domainvariants').jstree({ 
    plugins : ["themes","html_data","ui","crrm"] 
}).bind("select_node.jstree", function (event, data) { 
    return data.instance.toggle_node(data.node); 
}); 
+0

此代碼給我以下錯誤時,單擊一個項目:「未捕獲TypeError:無法調用方法'toggle_node'未定義」 – Jules 2013-11-20 06:36:20

+0

我有版本「jsTree 2.0.0-alpha」 – 2013-12-09 02:30:39