-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
42 lines (36 loc) · 1005 Bytes
/
index.js
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
function renderMenu(menu, parent) {
var el = $('<a href="#">' + menu.name + '</a>');
parent.append(el);
if (!menu.hasOwnProperty("contents")) {
return parent;
}
var ul = $('<ul/>');
for (var i = 0; i < menu.contents.length; ++i) {
var li = $('<li/>');
renderMenu(menu.contents[i], li);
ul.append(li);
}
parent.append(ul);
return parent;
}
function render(data) {
var div = $('<div/>');
return renderMenu(data, div);
}
$(function () {
var data = {
"type": "directory", "name": "haha", "contents": [
{"type": "file", "name": "2848"},
{
"type": "directory", "name": "_2848.extracted", "contents": [
{"type": "file", "name": "3A03FC.xz"}
]
}]
};
var menu = render(data);
$("#div").append(menu);
$("#div ul").css("display", "none");
$("#div a").on("click", function () {
$(this).next().toggle();
});
});