-
Notifications
You must be signed in to change notification settings - Fork 14
/
index.html
53 lines (48 loc) · 1.2 KB
/
index.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
InPut JSON:<textarea style="width: 100%;height: 200px;" id="input"></textarea>
OutPut JSON:<textarea style="width: 100%;height: 200px;" id="output"></textarea>
</body>
<script>
var input = document.getElementById("input");
input.addEventListener('input', function() {
var len = generateOutPut(this); // 调用函数
});
input.addEventListener('propertychange', function() { //兼容IE
var len = generateOutPut(this); // 调用函数
});
function generateOutPut() {
result = "";
var data = document.getElementById("input").value;
try {
if (data) {
data = JSON.parse(data);
data = data.data;
}
getMenuAll(data);
document.getElementById("output").value = result;
} catch (e) {}
}
var menuArr = [],
result = "";
function getMenuAll(arr) {
arr.filter(item => {
if (item && item.label) {
var tt = "";
for (var j = 1; j < item.level; j++) {
tt += "\t"
}
result += tt + item.label + "\t" + item.pnum + "\n"
}
if (item.children && item.children.length) {
getMenuAll(item.children)
}
})
}
</script>
</html>