tree数据格式
export default [{"title": "前端开发","key": "web","pid": 0,"id": 1,"children": [{"title": "React","key": "react","pid": 1,"id": 10,"children": [{"title": "虚拟DOM","key": "vdom","pid": 10,"id": 101},{"title": "组件化","key": "component","pid": 10,"id": 102},{"title": "react生命周期","key": "lifecycle","pid": 10,"id": 103}]},{"title": "Vue","key": "vue","pid": 1,"id": 12,"children": [{"title": "vuex","key": "vuex","pid": 12,"id": 121},{"title": "vue-router","key": "vue-router","pid": 12,"id": 122},{"title": "vue模板","key": "template","pid": 12,"id": 123}]},{"title": "ES6","key": "es6","id": 13,"pid": 1}]},{"title": "后端开发","key": "back","pid": 0,"id": 2,"children": [{"title": "搜索","key": "search","pid": 2,"id": 21,"children": [{"title": "缓存","key": "cache","pid": 21,"id": 211},{"title": "数据库","key": "sql","pid": 21,"id": 212},{"title": "Server","key": "server","pid": 21,"id": 213}]},{"title": "全文检索","key": "elastic","pid": 2,"id": 22}]},{"title": "产品运营","key": "operation","pid": 0,"id": 3}]
扁平化tree数组
export const isArray = array => Array.isArray(array) && array.lengthexport const flatArray = array => {if (!isArray(array)) return [];return array.reduce((memo, next) => {const flat = isArray(next.children) ? flatArray(next.children) : next;return memo.concat(flat);}, []);};
