<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
function deep(menuData) {
if (menuData && menuData.length > 0) {
return menuData.map(item => {
if (item.children && item.children.length > 0) {
item.url=item.path;
item.name=item.title;
deep(item.children)
}else{
item.url=item.path;
item.name=item.title;
}
return item;
})
}
}
const menuData = [
{
path: '/icon',
title: '图标',
},
{
path: '/components',
title: '常用组件',
children: [
{
path: '/components/editor',
title: '富文本',
},
{
path: 'test3',
title: '富文本2',
children:[
{ path: '富文本3',
title: '富文本3',
}
]
},
]
},
];
console.log(deep(menuData))
</script>
</body>
</html>
递归遍历树形图
最新推荐文章于 2025-04-21 18:04:32 发布