Skip to content

Instantly share code, notes, and snippets.

@YaoKaiLun
Created October 9, 2019 11:38
Show Gist options
  • Save YaoKaiLun/2daea80903b8e026402a075346aaa025 to your computer and use it in GitHub Desktop.
Save YaoKaiLun/2daea80903b8e026402a075346aaa025 to your computer and use it in GitHub Desktop.
/**
* Recursively flatten the data
* [{path:string},{path:string}] => {path,path2}
* @param menus
*/
export const getFlatMenuKeys = (menuData: MenuDataItem[] = []): string[] => {
let keys: string[] = [];
menuData.forEach(item => {
if (!item) {
return;
}
keys.push(item.path);
if (item.children) {
keys = keys.concat(getFlatMenuKeys(item.children));
}
});
return keys;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment