-
Notifications
You must be signed in to change notification settings - Fork 1
/
demo.html
128 lines (126 loc) · 2.87 KB
/
demo.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
.btn {
padding: 6px 12px;
margin: 30px 10px 20px;
border: 1px solid #dddee1;
border-radius: 4px;
text-align: center;
float: left;
font-size: 14px;
cursor: pointer;
user-select: none;
transition: all 0.1s;
}
.btn:hover {
background: #2d8cf0;
color: white;
}
.result {
clear: both;
font-size: 14px;
margin-left: 10px;
}
.result span {
margin: 10px;
}
a:link,a:visited,a:hover,a:active {
color: #0366D6;
}
</style>
</head>
<body>
<h4><a href="https://github.com/yeild/vtree">< GitHub</a></h4>
<div id="container"></div>
<div id="checkAll" class="btn">checkAll</div>
<div id="cancelAll" class="btn">cancelAll</div>
<div id="result" class="result"></div>
<script>
if (!window.vTree) {
document.write('<script src="./dist/vtree.min.js"><\/script>')
}
</script>
<script>
const data = [
{
title: 'parent 1',
children: [{
title: 'parent 1-1',
children: [{
title: 'leaf 1-1-1 long long long string',
checked: true
}, {
title: 'leaf 1-1-2',
}]
}, {
title: 'parent 1-2',
disabled: true,
children: [{
title: 'leaf 1-2-1'
}, {
checked: true,
title: 'leaf 1-2-2',
}, {
title: 'leaf 1-2-3'
}]
}]
}, {
title: 'parent 2',
children: [{
title: 'parent 2-1',
children: [{
title: 'leaf 2-1-1',
disabled: true
}, {
title: 'leaf 2-1-2'
}, {
title: 'parent 2-1-3',
expand: false,
children: [{
title: 'leaf 2-1-3-1'
}, {
title: 'leaf 2-1-3-2'
}, {
title: 'leaf 2-1-3-3'
}]
}]
}]
}]
const tree = vTree.init({
el: document.getElementById('container'),
data,
slice: 10,
showCheckbox: true,
onCheck: function (checkedNodes, event) {
console.log(checkedNodes)
console.log(event)
renderChecked()
}
})
document.getElementById('checkAll').addEventListener('click', function () {
tree.checkAll()
renderChecked()
})
document.getElementById('cancelAll').addEventListener('click', function () {
tree.cancelAll()
renderChecked()
})
function renderChecked () {
const checkedNode = tree.getCheckedNodes()
const fragment = document.createDocumentFragment()
checkedNode.forEach(node => {
const span = document.createElement('span')
span.innerHTML = node.title
fragment.appendChild(span)
})
const result = document.getElementById('result')
result.innerHTML = 'checked item: '
result.appendChild(fragment)
}
</script>
</body>
</html>