From 1a58dcac9537a08e94d27e01863841e043462f31 Mon Sep 17 00:00:00 2001 From: HeChengjun Date: Wed, 26 Apr 2017 16:16:35 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=20arrayToTree=20=E5=87=BD?= =?UTF-8?q?=E6=95=B0=E4=B8=AD=20children=20=E6=8B=BC=E5=86=99=E9=94=99?= =?UTF-8?q?=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/Layout/Menu.js | 4 ++-- src/utils/index.js | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/components/Layout/Menu.js b/src/components/Layout/Menu.js index 58c3d44..bd8d61a 100644 --- a/src/components/Layout/Menu.js +++ b/src/components/Layout/Menu.js @@ -13,7 +13,7 @@ const Menus = ({ siderFold, darkTheme, location, handleClickNavMenu, navOpenKeys // 递归生成菜单 const getMenus = (menuTreeN, siderFoldN) => { return menuTreeN.map(item => { - if (item.chindren) { + if (item.children) { if (item.mpid) { levelMap[item.id] = item.mpid } @@ -25,7 +25,7 @@ const Menus = ({ siderFold, darkTheme, location, handleClickNavMenu, navOpenKeys {(!siderFoldN || menuTree.indexOf(item) < 0) && item.name} } > - {getMenus(item.chindren, siderFoldN)} + {getMenus(item.children, siderFoldN)} ) } diff --git a/src/utils/index.js b/src/utils/index.js index e1e812c..52e5c08 100644 --- a/src/utils/index.js +++ b/src/utils/index.js @@ -79,7 +79,7 @@ const queryArray = (array, key, keyAlias = 'key') => { * @param {String} children * @return {Array} */ -const arrayToTree = (array, id = 'id', pid = 'pid', chindren = 'chindren') => { +const arrayToTree = (array, id = 'id', pid = 'pid', children = 'children') => { let data = lodash.cloneDeep(array) let result = [] let hash = {} @@ -90,8 +90,8 @@ const arrayToTree = (array, id = 'id', pid = 'pid', chindren = 'chindren') => { data.forEach((item) => { let hashVP = hash[item[pid]] if (hashVP) { - !hashVP[chindren] && (hashVP[chindren] = []) - hashVP[chindren].push(item) + !hashVP[children] && (hashVP[children] = []) + hashVP[children].push(item) } else { result.push(item) }