jquery easyUI combotree 只允許取捨葉子節點

來自 http://renxin-327666062-qq-com.iteye.com/blog/1543097 特此感謝

 
 
1.引入css和js 
Java代碼  收藏代碼
  1. <link rel="stylesheet" type="text/css" href="themes/default/easyui.css">  
  2. <script type="text/javascript" src="js/jquery-1.7.2.min.js"></script>  
  3. <script type="text/javascript" src="js/jquery.easyui.min.js"></script>  

2.加入標籤 
Java代碼  收藏代碼
  1. <input id="ddtree" name="ddtree" />  

注:id,用於js操作;name,用於獲取值 
3.加入js代碼 
Java代碼  收藏代碼
  1. $('#ddtree').combotree( {  
  2.     //獲取數據URL  
  3.     url : 'Data',  
  4.     //選擇樹節點觸發事件  
  5.     onSelect : function(node) {  
  6.         //返回樹對象  
  7.         var tree = $(this).tree;  
  8.         //選中的節點是否爲葉子節點,如果不是葉子節點,清除選中  
  9.         var isLeaf = tree('isLeaf', node.target);  
  10.         if (!isLeaf) {  
  11.             //清除選中  
  12.             $('#ddtree').combotree('clear');  
  13.         }  
  14.     }  
  15. });  

4.JSON格式 
Java代碼  收藏代碼
  1. [ {  
  2.     "id" : 1,  
  3.     "text" : "Folder1",  
  4.     "iconCls" : "icon-ok",  
  5.     "children" : [ {  
  6.         "id" : 2,  
  7.         "text" : "File1",  
  8.         "checked" : true  
  9.     }, {  
  10.         "id" : 3,  
  11.         "text" : "Folder2",  
  12.         "state" : "open",  
  13.         "children" : [ {  
  14.             "id" : 4,  
  15.             "text" : "File3",  
  16.             "attributes" : {  
  17.                 "p1" : "value1",  
  18.                 "p2" : "value2"  
  19.             },  
  20.             "checked" : true,  
  21.             "iconCls" : "icon-reload"  
  22.         }, {  
  23.             "id" : 8,  
  24.             "text" : "Async Folder",  
  25.             "state" : "closed"  
  26.         } ]  
  27.     } ]  
  28. }, {  
  29.     "text" : "Languages",  
  30.     "state" : "closed",  
  31.     "children" : [ {  
  32.         "id" : "j1",  
  33.         "text" : "Java"  
  34.     }, {  
  35.         "id" : "j2",  
  36.         "text" : "C#"  
  37.     } ]  
  38. } ]  

發佈了89 篇原創文章 · 獲贊 42 · 訪問量 86萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章