Javascript 如何在vue中按另一个数组筛选数组

Javascript 如何在vue中按另一个数组筛选数组,javascript,vue.js,filter,Javascript,Vue.js,Filter,我有两个对象数组,其中一个叫做子模块,子模块中有一个子数组,我需要通过访问对象数组来过滤这些子数组 newvue({ 数据:{ 子模块:[ { 键入:“something1”, 儿童:[ { 名称:“new_sth1”, 值:“new_sth1” }, { 名称:“新_sth2”, 值:“新的\u sth2” } ] }, { 键入:“something2”, 儿童:[ { 名称:“新_sth3”, 值:“new_sth3” }, ] }, { 键入:“something3”, 儿童:[ {

我有两个对象数组,其中一个叫做子模块,子模块中有一个子数组,我需要通过访问对象数组来过滤这些子数组

newvue({
数据:{
子模块:[
{
键入:“something1”,
儿童:[
{
名称:“new_sth1”,
值:“new_sth1”
},
{
名称:“新_sth2”,
值:“新的\u sth2”
}
]
},
{
键入:“something2”,
儿童:[
{
名称:“新_sth3”,
值:“new_sth3”
},
]
},
{
键入:“something3”,
儿童:[
{
名称:“新_sth4”,
值:“新的\u sth4”
},
{
名称:“新_sth5”,
值:“新_sth5”
},
{
名称:“新_sth6”,
值:“新的\u sth6”
},
]
},
],
访问:[
{value:'new_sth1'},
{value:'new_sth2'},
{value:'new_sth3'},
{value:'new_sth4'},
]
}
})

{{item.type}

您可以使用
computed
属性根据访问的
来过滤
子模块
数组

:代码未设置样式,因为我尚未安装引导

computed: {
    getFilteredResult() {
      return this.submodules.reduce((acc, curr) => {
        const children = curr.children.filter(({ value }) => {
          return this.accessed.find((x) => x.value === value);
        });
        acc.push({ ...curr, children });
        return acc;
      }, []);
    },
  },