gpt4 book ai didi

javascript - Angular Js在 Controller 中过滤嵌套数组

转载 作者:行者123 更新时间:2023-11-30 08:01:01 26 4
gpt4 key购买 nike

我想在 Controller 中使用 angularjs 过滤器过滤嵌套数组。以下是我的样本数据

dummy=[
{
category:'TV',
data:[
{
title: 'Game of Thrones',
path: 'some data1',
},
{
title: 'Game of Thrones-SD',
path: 'some data2'
},
{
title: 'Game of Thrones-HD',
path: 'some data3'
},
{
title: 'Game of Thrones-Trailer 1',
path: "some data4"
},
{
title: 'Game of Thrones-Trailer 2',
path: "some data5"
},
{
title: 'Game of Thrones-Trailer 3',
path: "Ssome data6"
},
{
title: 'The Vampire Diaries ',
path: 'some data7'
},
{
title: 'The Vampire Diaries -SD',
path: 'some data8'
},
{
title: 'The Vampire Diaries -HD',
path: 'some data9'
},
{
title: 'The Vampire Diaries -Trailer 1',
path: 'some data10'
}
]
},
{
category:'LIVE',
data:[
{
title: 'Game of Thrones - Live Show',
path: 'some data11'
},
{
title: 'The Vampire Diaries - Live Show',
path: 'some data11'
}
]
}
];

例如我想过滤标题上的数据,所以如果我搜索“权力的游戏”我想得到以下数据

    {
category:'TV',
data:[
{
title: 'Game of Thrones',
path: 'some data1',
},
{
title: 'Game of Thrones-SD',
path: 'some data2'
},
{
title: 'Game of Thrones-HD',
path: 'some data3'
},
{
title: 'Game of Thrones-Trailer 1',
path: "some data4"
},
{
title: 'Game of Thrones-Trailer 2',
path: "some data5"
},
{
title: 'Game of Thrones-Trailer 3',
path: "Ssome data6"
},
]
},
{
category:'LIVE',
data:[
{
title: 'Game of Thrones - Live Show',
path: 'some data11'
}
]
}

我想这里也有人问过类似的问题 Angularjs filter nested object

我尝试在我的 Controller 中使用以下代码,但没有成功

var filterdData = $filter('filter')(content, {data: [{title: $scope.filterKey}]});

最佳答案

这对我有用

var filterdData = $filter('filter')(content, {data: {title: $scope.filterKey}});

关于javascript - Angular Js在 Controller 中过滤嵌套数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28392651/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com