From 34e69e55ee5194691991f2e34eb7258d5d485c4b Mon Sep 17 00:00:00 2001 From: afc163 Date: Wed, 3 Jan 2018 14:48:31 +0800 Subject: [PATCH] refactor formatter --- src/common/menu.js | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/src/common/menu.js b/src/common/menu.js index e73b95b3..e910d764 100644 --- a/src/common/menu.js +++ b/src/common/menu.js @@ -115,22 +115,16 @@ const menuData = [{ }]; function formatter(data, parentPath = '') { - const list = []; - data.forEach((item) => { + return data.map((item) => { + const result = { + ...item, + path: `${parentPath}${item.path}`, + }; if (item.children) { - list.push({ - ...item, - path: `${parentPath}${item.path}`, - children: formatter(item.children, `${parentPath}${item.path}/`), - }); - } else { - list.push({ - ...item, - path: `${parentPath}${item.path}`, - }); + result.children = formatter(item.children, `${parentPath}${item.path}/`); } + return result; }); - return list; } export const getMenuData = () => formatter(menuData); -- GitLab