forked from layui/layui
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtree.html
More file actions
254 lines (240 loc) · 5.57 KB
/
Copy pathtree.html
File metadata and controls
254 lines (240 loc) · 5.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<title>树组件 - layui</title>
<link rel="stylesheet" href="../src/css/layui.css" media="all">
<style>
body{padding: 100px;}
#test1,#test2{margin-bottom: 100px; width: 400px;}
</style>
</head>
<body>
<div class="layui-btn-container">
<button type="button" class="layui-btn" lay-demo="getChecked">获取选中数据</button>
<button type="button" class="layui-btn" lay-demo="setChecked">设置节点勾选</button>
<button type="button" class="layui-btn" lay-demo="reload">重载实例</button>
</div>
<div class="layui-form">
<div class="layui-form-item">
<label class="layui-form-label">表单内</label>
<div class="layui-input-block">
</div>
</div>
<div id="test1"></div>
<div id="test2"></div>
<script src="../src/layui.js"></script>
<script>
layui.use(['tree', 'layer', 'util'], function(){
var $ = layui.$
,tree = layui.tree
,layer = layui.layer
,util = layui.util
,index = 100;
//数据源
var data1 = [{
title: 'A-1'
,id: 1
,children: [{
title: 'B-1-1'
,id: 3
,href: 'https://www.layui.com/doc/'
,children: [{
title: 'C-1-1-3'
,id: 23
,children: [{
title: 'D-1-1-3-1'
,id: 24
,children: [{
title: 'E-1-1-3-1-1'
,id: 30
},{
title: 'E-1-1-3-1-2'
,id: 31
}]
}]
},{
title: 'C-1-1-1'
,id: 7
,checked: true
,children: [{
title: 'D-1-1-1-1'
,id: 15
//,checked: true
,href: 'https://www.layui.com/doc/base/infrastructure.html'
}]
},{
title: 'C-1-1-2'
,id: 8
,children: [{
title: 'D-1-1-2-1'
,id: 32
}]
}]
},{
title: 'B-1-2'
,id: 4
,spread: true
,children: [{
title: 'C-1-2-1'
,id: 9
,checked: true
,disabled: true
},{
title: 'C-1-2-2'
,id: 10
}]
},{
title: 'B-1-3'
,id: 20
,children: [{
title: 'C-1-3-1'
,id: 21
},{
title: 'C-1-3-2'
,id: 22
}]
}]
},{
title: 'A-2'
,id: 2
,spread: true
,children: [{
title: 'B-2-1'
,id: 5
,spread: true
,children: [{
title: 'C-2-1-1'
,id: 11
},{
title: 'C-2-1-2'
,id: 12
}]
},{
title: 'B-2-2'
,id: 6
,checked: true
,children: [{
title: 'C-2-2-1'
,id: 13
},{
title: 'C-2-2-2'
,id: 14
,disabled: true
}]
}]
},{
title: 'A-3'
,id: 16
,children: [{
title: 'B-3-1'
,id: 17
,fixed: true
,children: [{
title: 'C-3-1-1'
,id: 18
},{
title: 'C-3-1-2'
,id: 19
}]
},{
title: 'B-3-2'
,id: 27
,children: [{
title: 'C-3-2-1'
,id: 28
},{
title: 'C-3-2-2'
,id: 29
}]
}]
}];
//数据源
var data2 = [{
title: '控制台'
,id: '1000'
,spread: true
,checked: true
,children: [{
title: '概览'
,id: '1001'
,spread: true
,checked: true
},{
title: '域名'
,id: '1002'
,spread: true
,checked: true
}]
}]
tree.render({
elem: '#test1'
,data: data1
,id: 'demoId1'
,click: function(obj){
layer.msg(JSON.stringify(obj.data));
console.log(obj);
}
,oncheck: function(obj){
//console.log(obj);
}
,operate: function(obj){
var type = obj.type;
if(type == 'add'){
//ajax操作,返回key值
return index++;
}else if(type == 'update'){
console.log(obj.elem.find('.layui-tree-txt').html());
}else if(type == 'del'){
console.log(obj);
};
}
,showCheckbox: true //是否显示复选框
,accordion: 0 //是否开启手风琴模式
,onlyIconControl: true //是否仅允许节点左侧图标控制展开收缩
,isJump: 0 //点击文案跳转地址
,edit: true //操作节点图标
});
//按钮事件
util.event('lay-demo', {
getChecked: function(othis){
var checkedData = tree.getChecked('demoId1');
layer.alert(JSON.stringify(checkedData), {shade:0});
console.log(checkedData);
}
,setChecked: function(){
tree.setChecked('demoId1', [11,12]);
}
,reload: function(){
tree.reload('demoId1', {
});
}
});
tree.render({
elem: '#test2'
,data: data1
//,expandClick: false
,showLine: false //关闭连接线
,click: function(obj, state){
console.log(obj);
}
,oncheck: function(obj, checked, child){
if(checked){
console.log(obj[0]);
}
}
,onsearch: function(data, num){
console.log(num);
}
,dragstart: function(obj, parent){
console.log(obj, parent);
}
,dragend: function(state, obj, target){
console.log(state, obj, target);
}
});
});
</script>
</body>
</html>