//选出menuSetting的子数组(元素在arr中存在)
let menunew = menuSetting.filter(v => arr.includes(v.name))
//类似于下面的数据结构,你在想去掉children中的某个对象时候,用splice的时候,需要用倒叙循环法(splice的bug)
menunew.map((v, index) => {
for (let i = v.children.length - 1; i >= 0; i--) {
if (!arr.includes(v.children[i].name)) {
v.children.splice(i, 1)
}
}
})
//
[
{
name: '综合安防',
children: [
{
to: '/index/videoaggregation',
icon: 'app-icon-videoaggregation', // 视频汇聚
name: '视频汇聚'
},
{
to: '/index/securityprevent',
icon: 'app-icon-securityprevent', // 安全防范
name: '安全防范'
},
{
to: '/index/patrolsystem',
icon: 'app-icon-patrolsystem', // 电子巡更
name: '电子巡更'
}
]
}
]
遍历循环 礼记
最新推荐文章于 2024-05-06 12:55:47 发布