1.解决for循环发异步请求,并确定全部请求返回后 开始回调
Promise.all(reqs).then(function (values) {
//一次性执行完所有请求后回调
values.forEach(function (res,index) {
if (res.status ==200) {
parentMenu[index].children=res.data.message;
}
})
vm.allMunuList=flatten(parentMenu);
vm.menuList=vm.allMunuList;
});
2.树形结构json 扁平化处理
<script>
var data=[
{
"name":"栏目管理",
"url":"/info/mng/type_mng.html",
"mainType":false,
"enabled":true,
"children":[
]
},
{
"name":"卫生保健",
"typeId":"info12",
"url":"/app/index.html#/application/notice?typeId=info12",
"mainType":false,
"enabled":true,
"children":[
{
"name":"每周食谱",
"typeId":"info1201",
"url":"/app/index.html#/application/notice?typeId=info1201",
"mainType":false,
"enabled":true,
"children":[
]
},
{
"name":"幼儿出勤",
"typeId":"info1204",
"url":"/app/index.html#/application/notice?typeId=info1204",
"mainType":false,
"enabled":true,
"children":[
]
},
{
"name":"膳食分析",
"typeId":"info1202",
"url":"/app/index.html#/application/notice?typeId=info1202",
"mainType":false,
"enabled":true,
"children":[
]
},
{
"name":"因病缺席幼儿跟踪",
"typeId":"info1203",
"url":"/app/index.html#/application/notice?typeId=info1203",
"mainType":false,
"enabled":true,
"children":[
]
}
]
},
{
"name":"园内通知",
"typeId":"info01",
"url":"/app/index.html#/application/notice?typeId=info01",
"mainType":true,
"enabled":true,
"children":[
{
"name":"上级通知",
"typeId":"info0101",
"url":"/app/index.html#/application/notice?typeId=info0101",
"mainType":false,
"enabled":true,
"children":[
{
"name":"333333",
"typeId":"info010101",
"url":"/app/index.html#/application/notice?typeId=info010101",
"mainType":false,
"enabled":true
}
]
},
{
"name":"行政通知",
"typeId":"info0102",
"url":"/app/index.html#/application/notice?typeId=info0102",
"mainType":false,
"enabled":true
}
]
},
{
"name":"校园动态",
"typeId":"info13",
"url":"/app/index.html#/application/notice?typeId=info13",
"mainType":false,
"enabled":true,
"children":[
{
"name":"校园动态",
"typeId":"info1301",
"url":"/app/index.html#/application/notice?typeId=info1301",
"mainType":false,
"enabled":true,
"children":[
]
}
]
},
{
"name":"党建工作",
"typeId":"info02",
"url":"/app/index.html#/application/notice?typeId=info02",
"mainType":false,
"enabled":true,
"children":[
{
"name":"党员学习",
"typeId":"info0202",
"url":"/app/index.html#/application/notice?typeId=info0202",
"mainType":false,
"enabled":true,
"children":[
]
},
{
"name":"党务公开",
"typeId":"info0201",
"url":"/app/index.html#/application/notice?typeId=info0201",
"mainType":false,
"enabled":true,
"children":[
]
},
{
"name":"党建文件",
"typeId":"info0203",
"url":"/app/index.html#/application/notice?typeId=info0203",
"mainType":false,
"enabled":true,
"children":[
]
}
]
},
{
"name":"人力资源",
"typeId":"info10",
"url":"/app/index.html#/application/notice?typeId=info10",
"mainType":false,
"enabled":true,
"children":[
{
"name":"职称评聘",
"typeId":"info1002",
"url":"/app/index.html#/application/notice?typeId=info1002",
"mainType":false,
"enabled":true,
"children":[
]
},
{
"name":"人员异动",
"typeId":"info1003",
"url":"/app/index.html#/application/notice?typeId=info1003",
"mainType":false,
"enabled":true,
"children":[
]
},
{
"name":"人事信息",
"typeId":"info1001",
"url":"/app/index.html#/application/notice?typeId=info1001",
"mainType":false,
"enabled":true,
"children":[
]
},
{
"name":"获奖登记",
"typeId":"info1004",
"url":"/app/index.html#/application/notice?typeId=info1004",
"mainType":false,
"enabled":true,
"children":[
]
}
]
},
{
"name":"安全保卫",
"typeId":"info11",
"url":"/app/index.html#/application/notice?typeId=info11",
"mainType":false,
"enabled":true,
"children":[
{
"name":"安全保卫",
"typeId":"info1101",
"url":"/app/index.html#/application/notice?typeId=info1101",
"mainType":false,
"enabled":true,
"children":[
]
}
]
},
{
"name":"督导信息",
"typeId":"info05",
"url":"/app/index.html#/application/notice?typeId=info05",
"mainType":false,
"enabled":true,
"children":[
{
"name":"记录表",
"typeId":"info0501",
"url":"/app/index.html#/application/notice?typeId=info0501",
"mainType":false,
"enabled":true,
"children":[
]
},
{
"name":"公示表",
"typeId":"info0502",
"url":"/app/index.html#/application/notice?typeId=info0502",
"mainType":false,
"enabled":true,
"children":[
]
}
]
},
{
"name":"课程教学",
"typeId":"info06",
"url":"/app/index.html#/application/notice?typeId=info06",
"mainType":false,
"enabled":true,
"children":[
{
"name":"家园活动",
"typeId":"info0605",
"url":"/app/index.html#/application/notice?typeId=info0605",
"mainType":false,
"enabled":true,
"children":[
]
},
{
"name":"班级管理",
"typeId":"info0606",
"url":"/app/index.html#/application/notice?typeId=info0606",
"mainType":false,
"enabled":true,
"children":[
]
},
{
"name":"读书分享",
"typeId":"info0603",
"url":"/app/index.html#/application/notice?typeId=info0603",
"mainType":false,
"enabled":true,
"children":[
]
},
{
"name":"教师随笔",
"typeId":"info0604",
"url":"/app/index.html#/application/notice?typeId=info0604",
"mainType":false,
"enabled":true,
"children":[
]
},
{
"name":"教师备课",
"typeId":"info0601",
"url":"/app/index.html#/application/notice?typeId=info0601",
"mainType":false,
"enabled":true,
"children":[
]
},
{
"name":"年级活动",
"typeId":"info0602",
"url":"/app/index.html#/application/notice?typeId=info0602",
"mainType":false,
"enabled":true,
"children":[
]
}
]
},
{
"name":"园务公开",
"typeId":"info03",
"url":"/app/index.html#/application/notice?typeId=info03",
"mainType":false,
"enabled":true,
"children":[
{
"name":"工程建设",
"typeId":"info0308",
"url":"/app/index.html#/application/notice?typeId=info0308",
"mainType":false,
"enabled":true,
"children":[
]
},
{
"name":"学期计划、总结",
"typeId":"info0301",
"url":"/app/index.html#/application/notice?typeId=info0301",
"mainType":false,
"enabled":true,
"children":[
]
},
{
"name":"周工作安排",
"typeId":"info0303",
"url":"/app/index.html#/application/notice?typeId=info0303",
"mainType":false,
"enabled":true,
"children":[
]
},
{
"name":"月工作安排",
"typeId":"info0302",
"url":"/app/index.html#/application/notice?typeId=info0302",
"mainType":false,
"enabled":true,
"children":[
]
},
{
"name":"每月大事记",
"typeId":"info0305",
"url":"/app/index.html#/application/notice?typeId=info0305",
"mainType":false,
"enabled":true,
"children":[
]
},
{
"name":"活动快讯",
"typeId":"info0304",
"url":"/app/index.html#/application/notice?typeId=info0304",
"mainType":false,
"enabled":true,
"children":[
]
},
{
"name":"会议纪要",
"typeId":"info0307",
"url":"/app/index.html#/application/notice?typeId=info0307",
"mainType":false,
"enabled":true,
"children":[
]
},
{
"name":"月、学期考核",
"typeId":"info0306",
"url":"/app/index.html#/application/notice?typeId=info0306",
"mainType":false,
"enabled":true,
"children":[
]
}
]
},
{
"name":"工会活动",
"typeId":"info04",
"url":"/app/index.html#/application/notice?typeId=info04",
"mainType":false,
"enabled":true,
"children":[
{
"name":"工会活动",
"typeId":"info0401",
"url":"/app/index.html#/application/notice?typeId=info0401",
"mainType":false,
"enabled":true,
"children":[
]
}
]
},
{
"name":"教育科研",
"typeId":"info09",
"url":"/app/index.html#/application/notice?typeId=info09",
"mainType":false,
"enabled":true,
"children":[
{
"name":"课题组活动",
"typeId":"info0904",
"url":"/app/index.html#/application/notice?typeId=info0904",
"mainType":false,
"enabled":true,
"children":[
]
},
{
"name":"体育组活动",
"typeId":"info0905",
"url":"/app/index.html#/application/notice?typeId=info0905",
"mainType":false,
"enabled":true,
"children":[
]
},
{
"name":"月主题活动",
"typeId":"info0902",
"url":"/app/index.html#/application/notice?typeId=info0902",
"mainType":false,
"enabled":true,
"children":[
]
},
{
"name":"教研组活动",
"typeId":"info0903",
"url":"/app/index.html#/application/notice?typeId=info0903",
"mainType":false,
"enabled":true,
"children":[
]
},
{
"name":"保育教研",
"typeId":"info0906",
"url":"/app/index.html#/application/notice?typeId=info0906",
"mainType":false,
"enabled":true,
"children":[
]
},
{
"name":"教研通知",
"typeId":"info0901",
"url":"/app/index.html#/application/notice?typeId=info0901",
"mainType":false,
"enabled":true,
"children":[
]
}
]
},
{
"name":"培训研修",
"typeId":"info07",
"url":"/app/index.html#/application/notice?typeId=info07",
"mainType":false,
"enabled":true,
"children":[
{
"name":"家长学校",
"typeId":"info0706",
"url":"/app/index.html#/application/notice?typeId=info0706",
"mainType":false,
"enabled":true,
"children":[
]
},
{
"name":"草根讲坛",
"typeId":"info0704",
"url":"/app/index.html#/application/notice?typeId=info0704",
"mainType":false,
"enabled":true,
"children":[
]
},
{
"name":"见习生管理",
"typeId":"info0705",
"url":"/app/index.html#/application/notice?typeId=info0705",
"mainType":false,
"enabled":true,
"children":[
]
},
{
"name":"继续教育",
"typeId":"info0702",
"url":"/app/index.html#/application/notice?typeId=info0702",
"mainType":false,
"enabled":true,
"children":[
]
},
{
"name":"外出学习",
"typeId":"info0703",
"url":"/app/index.html#/application/notice?typeId=info0703",
"mainType":false,
"enabled":true,
"children":[
]
},
{
"name":"青年教师培训",
"typeId":"info0701",
"url":"/app/index.html#/application/notice?typeId=info0701",
"mainType":false,
"enabled":true,
"children":[
]
}
]
},
{
"name":"专题活动",
"typeId":"info08",
"url":"/app/index.html#/application/notice?typeId=info08",
"mainType":false,
"enabled":true,
"children":[
{
"name":"开放日活动",
"typeId":"info0803",
"url":"/app/index.html#/application/notice?typeId=info0803",
"mainType":false,
"enabled":true,
"children":[
]
},
{
"name":"活动简报",
"typeId":"info0804",
"url":"/app/index.html#/application/notice?typeId=info0804",
"mainType":false,
"enabled":true,
"children":[
]
},
{
"name":"教研活动",
"typeId":"info0801",
"url":"/app/index.html#/application/notice?typeId=info0801",
"mainType":false,
"enabled":true,
"children":[
]
},
{
"name":"专题组活动",
"typeId":"info0802",
"url":"/app/index.html#/application/notice?typeId=info0802",
"mainType":false,
"enabled":true,
"children":[
]
}
]
},
{
"name":"公文管理",
"typeId":"offi01",
"url":"/app/index.html#/application/archives?typeId=offi01",
"mainType":true,
"enabled":true,
"children":[
]
},
{
"name":"内部审批",
"typeId":"docu01",
"url":"/app/index.html#/application/file?typeId=docu01",
"mainType":true,
"enabled":true,
"children":[
]
}
];
function flatten (data,blank=6) {
return data.reduce((arr, {name, typeId, url, mainType,enabled,children =[]}) =>
arr.concat([{blank,name, typeId, url, mainType,enabled}], flatten(children,blank+2)), [])
}
// function flatten (data, level = 0) {
// return data.reduce((arr, {Id, Name, Pid, id, children = []}) =>
// arr.concat([{level, Id, Name, Pid, id}], flatten(children, level+1)), [])
// }
function aaa() {
console.log(data)
var ss=flatten(data);
console.log(ss);
}
</script>