我在我的vuetify项目中有抽屉,它包含下拉菜单,我正在使用它访问每个下拉菜单,它工作得很好,但它过滤了它下拉菜单中的所有内容,但我想要的是过滤特定的子项,我该怎么做呢?这就是我尝试过的
<script>
export default {
data: () => ({
permission: '',
filtereditems: [],
items: [
{
group: '/group1',
title: 'school',
children: [
{
title: 'teachers',
},
{
title: 'students',
},
],
},
{
group: '/group12',
title: 'hostpital',
children: [
{
title: 'doctor',
},
{
title: 'patient',
},
],
},
],
)},
created () {
this.permission = localStorage.getItem('permissions')
const per = this.permission
console.log(per)
if (per === 'school') {
this.filtereditems = this.items.filter(item => (item.title === 'school'))
this.filtereditems = this.items.children.filter(item => (item.title === 'teacher'))
} else if (per === 'hostpital') {
this.filtereditems = this.items.filter(item => (item.title === 'hostpital'))
}
},
}
</script>this.filtereditems = this.items.filter(item => (item.title === 'school'))筛选器可以对学校下拉列表进行筛选,但this.filtereditems = this.items.children.filter(item => (item.title === 'teacher'))不会筛选子项


发布于 2020-05-20 17:17:19
不筛选子项
它更像是找不到任何匹配
如果您要在字符串中查找一个短语,无论它在哪里,都可以使用string.includes
item.title.includes('school')--编辑
获取子项的示例代码
const data = {
filtereditems: [],
items: [{
group: '/group1',
title: 'school',
children: [{
title: 'teachers',
},
{
title: 'students',
},
],
},
{
group: '/group12',
title: 'hostpital',
children: [{
title: 'doctor',
},
{
title: 'patient',
},
],
},
]
}
data.filtereditems = data.items.find(item => item.title.includes('school'))
data.filtereditems = data.filtereditems.children.find(item => !item.title.includes('teachers'))
console.log(data.filtereditems);
https://stackoverflow.com/questions/61909242
复制相似问题