var _json = {
"children": [{
"children": [{
"children": [{
"children": [],
"content": "",
"distance": 0,
"id": 350,
"order": "1",
"par_id": 318,
"paragraph_id": 470,
"text": "新5",
"state": "open",
"domId": "_easyui_tree_14",
"target": {"pageY": 146}
}, {
"children": [],
"content": "",
"distance": 0,
"id": 320,
"order": "2",
"par_id": 6,
"paragraph_id": 440,
"text": "进攻打法",
"state": "open",
"domId": "_easyui_tree_4"
}, {
"children": [],
"content": "",
"distance": 0,
"id": 321,
"order": "3",
"par_id": 6,
"paragraph_id": 441,
"text": "中场打法",
"state": "open",
"domId": "_easyui_tree_5"
}],
"content": "",
"distance": 0,
"id": 6,
"order": "(二).",
"par_id": 4,
"paragraph_id": 230,
"text": "门诊工作",
"state": "open",
"domId": "_easyui_tree_3",
"target": {"jQuery11130507155963828726": 50}
}, {
"children": [],
"content": "",
"distance": 0,
"id": 7,
"order": "(三).",
"par_id": 4,
"paragraph_id": 240,
"text": "医技科室",
"state": "open",
"domId": "_easyui_tree_6"
}, {
"children": [{
"children": [],
"content": "",
"distance": 0,
"id": 351,
"order": "2",
"par_id": 318,
"paragraph_id": 471,
"text": "新1",
"state": "open",
"domId": "_easyui_tree_9"
}, {
"children": [],
"content": "",
"distance": 0,
"id": 352,
"order": "3",
"par_id": 318,
"paragraph_id": 472,
"text": "示范点",
"state": "open",
"domId": "_easyui_tree_10"
}, {
"children": [],
"content": "",
"distance": 0,
"id": 353,
"order": "4",
"par_id": 318,
"paragraph_id": 473,
"text": "发生大",
"state": "open",
"domId": "_easyui_tree_11"
}, {
"children": [],
"content": "",
"distance": 0,
"id": 354,
"order": "5",
"par_id": 318,
"paragraph_id": 474,
"text": "选择",
"state": "open",
"domId": "_easyui_tree_12"
}],
"content": "",
"distance": 0,
"id": 318,
"order": "(四).",
"par_id": 4,
"paragraph_id": 438,
"text": "发生大",
"state": "open",
"domId": "_easyui_tree_7",
"target": {"jQuery11130507155963828726": 66, "entered": false}
}],
"content": "",
"distance": 0,
"id": 4,
"order": "一.",
"par_id": 1,
"paragraph_id": 230,
"text": "医疗质控工作小结",
"state": "open",
"domId": "_easyui_tree_2",
"target": {"jQuery11130507155963828726": 46}
}, {
"children": [],
"content": "",
"distance": 0,
"id": 8,
"order": "二.",
"par_id": 1,
"paragraph_id": 230,
"text": "整改意见",
"state": "open",
"domId": "_easyui_tree_13"
}],
"content": "",
"distance": 0,
"id": 1,
"order": "",
"par_id": 0,
"paragraph_id": 240,
"text": "目录",
"state": "open",
"domId": "_easyui_tree_1",
"target": {"jQuery11130507155963828726": 42}
};
//利用for循环,IIFE函数
forJson(_json);
function forJson(arr) {
if (arr.children.length) {
console.log(arr,"par");
for (var i = 0; i < arr.children.length; i++) {
!function (j) {
forJson(arr.children[j]);
}(i)
}
} else {
console.log(arr,"son"); //循环打出不是目录下的
}
}
// 利用数组map
mapJson(_json);
function mapJson(json) {
json.children.map(function(val,index){
val.children.length ?console.log(val,"par") & mapJson(val) : console.log(val,"son");
})
}
网友评论