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

标签 javascript angularjs filter

我想在 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/

相关文章:

javascript - 如何修复我的 js 绑定(bind)实现?

javascript - 下拉按钮在 Bootstrap 中无法正常工作。有人能告诉我哪里出错了吗

ajax - Angular JS *非 SPA* SEO

csv - awk:如何过滤掉所有条目(16 列)都为 0 的行

javascript - 使用 JS 寻找我的过滤器函数的较短版本

javascript - 是否可以使用非鼠标、非触摸事件与 D3.js 图表进行交互?如果是这样,最有效的方法是什么?

javascript - angularjs 无法更新下拉列表更改时的指令

javascript - 我的 AngularJs 应用程序不会转发到另一个网站

AngularJS : Chrome hidden fields value don't update after page return

使用 graphql 在 magento2 中使用自定义属性过滤产品会导致错误 : Field is not defined by type ProductAttributeFilterInput