From 9053dad3c3de5b69b67bb0037575b731365a5855 Mon Sep 17 00:00:00 2001 From: chenshuai2144 Date: Sat, 18 Jul 2020 21:43:59 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20bug:=20children=20is=20null=20us?= =?UTF-8?q?e=20hasChildren?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/SiderMenu/BaseMenu.tsx | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/SiderMenu/BaseMenu.tsx b/src/SiderMenu/BaseMenu.tsx index d6bed7af..43ac39fc 100644 --- a/src/SiderMenu/BaseMenu.tsx +++ b/src/SiderMenu/BaseMenu.tsx @@ -105,6 +105,15 @@ class MenuUtil { .map((item) => this.getSubMenuOrItem(item, isChildren)) .filter((item) => item); + hasChildren = (item: MenuDataItem) => { + return ( + item && + !item.hideChildrenInMenu && + item?.children && + item.children.some((child) => child && !!child.name && !child.hideInMenu) + ); + }; + /** * get SubMenu or Item */ @@ -112,11 +121,7 @@ class MenuUtil { item: MenuDataItem, isChildren: boolean, ): React.ReactNode => { - if ( - Array.isArray(item.children) && - !item.hideChildrenInMenu && - item.children.some((child) => child && !!child.name && !child.hideInMenu) - ) { + if (Array.isArray(item.children) && this.hasChildren(item)) { const name = this.getIntlName(item); const { subMenuItemRender } = this.props; // get defaultTitle by menuItemRender @@ -214,7 +219,7 @@ class MenuUtil { onClick: () => onCollapse && onCollapse(true), }; // 如果 hideChildrenInMenu 删除掉无用的 children - if (renderItemProps.hideChildrenInMenu) { + if (!this.hasChildren(item)) { delete renderItemProps.children; } return menuItemRender(renderItemProps, defaultItem);