json2table.js
1.74 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
var data = {
"errcode": 0,
"errmsg": "ok",
"errsdkcode": "",
"requestId": "",
"timestamp": 1487016662000,
"result": {
"list": [{
"a_id": "1",
"at_id": "1",
"number": "1",
"mem_uid": "D0A0C79B7F0000013DC51B614A038FDF",
"title": "1212",
"dp_id": "1",
"start_time": "1",
"end_time": "2",
"leave_time": "1",
"approve_status": "1",
"is_abnormal": "1",
"created": "1",
"is_abnormal_desc": "正常",
"approve_status_desc": "审批中",
"dp_name": [{
"dp_id": "1",
"dp_name": null
}],
"mem_name": [{
"mem_uid": "D0A0C79B7F0000013DC51B614A038FDF",
"mem_name": "张帅",
"mem_face": "http://shp.qpic.cn/bizmp/b28orD0nfSzX1Lln6mxlicyejcySrMOn9RmichgR1IQ0f8079m3ODicCw/"
}],
"at_name": "1"
}],
"total": "1",
"page": 1,
"limit": 15
}
};
function json2table(data, upNode) {
var showItems = '';
for(var key in data) {
var showKey = upNode+"."+key;
var showType = typeof data[key];
if(Array.isArray(data[key])) {
showKey += "[]"
showType = 'array'
}
showItems += "\n||!!#3366ff " + showKey + " !! ||!!#5566ff " + showType + " !! || "
+ data[key] + " ||";
if(showType == 'object') {
showItems += json2table(data[key], showKey);
} else if(showType == 'array') {
showItems += json2table(data[key][0], showKey);
}
}
return showItems;
}
console.log(json2table(data, ''));