toFullPath method
转换 List 菜单集合,此函数通常用于路由中,它会将嵌套子菜单的 key 转换成完整路径(拼接父级 key 地址)
Implementation
List<ElMenuModel<T>> toFullPath({String? parentPath}) {
List<ElMenuModel<T>> buildNestPaths(List<ElMenuModel<T>> menus, String? parentPath) {
return menus.map((menu) {
final currentPath = _buildFullPath(parentPath, menu.key);
final newMenu = ElMenuModel<T>(
key: currentPath,
title: menu.title,
data: menu.data,
children: menu.children.isNotEmpty ? buildNestPaths(menu.children, currentPath) : [],
);
return newMenu;
}).toList();
}
return buildNestPaths(this, parentPath);
}