jquery easyUI combotree 只允許取捨葉子節點
阿新 • • 發佈:2019-02-15
1.引入css和js
Java程式碼
- <link rel="stylesheet" type="text/css" href="themes/default/easyui.css">
- <script type="text/javascript" src="js/jquery-1.7.2.min.js"></script>
- <script type="text/javascript" src="js/jquery.easyui.min.js"></script>
2.加入標籤
Java程式碼
-
<input id="ddtree"
注:id,用於js操作;name,用於獲取值
3.加入js程式碼
Java程式碼
- $('#ddtree').combotree( {
- //獲取資料URL
- url : 'Data',
- //選擇樹節點觸發事件
- onSelect : function(node) {
- //返回樹物件
- var tree = $(this).tree;
- //選中的節點是否為葉子節點,如果不是葉子節點,清除選中
-
var isLeaf = tree('isLeaf'
- if (!isLeaf) {
- //清除選中
- $('#ddtree').combotree('clear');
- }
- }
- });
4.JSON格式
Java程式碼
- [ {
- "id" : 1,
- "text" : "Folder1",
- "iconCls" : "icon-ok",
- "children" : [ {
- "id" : 2,
-
"text" : "File1"
- "checked" : true
- }, {
- "id" : 3,
- "text" : "Folder2",
- "state" : "open",
- "children" : [ {
- "id" : 4,
- "text" : "File3",
- "attributes" : {
- "p1" : "value1",
- "p2" : "value2"
- },
- "checked" : true,
- "iconCls" : "icon-reload"
- }, {
- "id" : 8,
- "text" : "Async Folder",
- "state" : "closed"
- } ]
- } ]
- }, {
- "text" : "Languages",
- "state" : "closed",
- "children" : [ {
- "id" : "j1",
- "text" : "Java"
- }, {
- "id" : "j2",
- "text" : "C#"
- } ]
- } ]