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");
})
}
遍历json
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 需求 当我们用 for(var i in json)时, 如果是第一种形式, 那没什么问题,就是取的我们想要的数据...
- 背景 Thymeleaf模版很多地方确实很方便,但是在处理JSON对象时遇到了一些问题,就觉得很有意思记录一下,以...
- 动画原理 人走路的时候, 步长动画的基本原理 : 让盒子的 offsetLeft + 步长 盒子 原来的...