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}
};
function Init(obj){
this.text=obj.text;
this.id=obj.id;
this.order=obj.order;
this.children=[];
this.par_id=obj.obj;
this.paragraph_id=obj.paragraph_id;
this.distance=obj.distance;
this.content=obj.content;
}
function recursion(obj, tempObj,_arr) {
if(obj.children.length>0){
var addArr=[];
for (var i = 0; i < obj.children.length; i++) {
!function (i) {
addArr.push(obj.children[i])
}(i)
if (i==obj.children.length-1) {/*添加完*/
tempObj=addArr.concat(tempObj);
var temp = JSON.stringify(tempObj[0]);
temp=JSON.parse(temp);
var item = {
"text": temp.text,
"id": temp.id,
"order": temp.order,
"children": [],
}
_arr.push( new Init(temp));
var del=tempObj.shift();/*删掉头部*/
if(del.children.length>0){
recursion(del, tempObj, _arr)
}else{
for (var j = 0,leg=tempObj.length; j <leg; j++) {
if(tempObj[0].children.length>0){
var _del= tempObj.shift();/*删掉头部*/
_del = JSON.stringify(_del);
_del=JSON.parse(_del);
_arr.push( new Init(_del));
recursion(_del, tempObj, _arr);
break;
}else{
var _del= tempObj.shift();/*删掉头部*/
_del = JSON.stringify(_del);
_del=JSON.parse(_del);
_arr.push( new Init(_del));
}
}
}
}
}
}else{
return ;
}
}
var _arrs = [] ,workSpace=[];
_arrs.push( new Init(_json));
recursion(_json, workSpace,_arrs);
打平json成为数组
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- JS - 字符串- 数组- 对象- json- http://www.w3school.com.cn/json/j...
- 回顾: 数组: var arr=[1,2,3,4]; var arr=new Array(1,2,3,4,5);区...
- 问题描述 有时候因为业务的需要,有些字段不但是json格式,并且还是个json数组,比如下表 pay_infos:...
- 推荐一个网站,建议大家去看看怎样快速而优雅地遍历 JavaScript 数组 第一段 场景:php将数据取出便利到...