Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在嵌套Json中使用angularjs进行过滤_Javascript_Angularjs_Json_Search_Filter - Fatal编程技术网

Javascript 如何在嵌套Json中使用angularjs进行过滤

Javascript 如何在嵌套Json中使用angularjs进行过滤,javascript,angularjs,json,search,filter,Javascript,Angularjs,Json,Search,Filter,我需要一个嵌套在JSON数组中的查询,如下所示。 我想检查一下我的名字是否是约翰,我的爱好是否有运动,但它不起作用 以下类似代码的结果: [ {"id":1,"name":"John","hobbies":[{"kind":"sport"},{"kind":"music"}]}, {"id":5,"name":"John","hobbies":[{"kind":"swimming"},{"kind":"opera"}]} ] 但它必须是{code>{id:1,“name”:“John

我需要一个嵌套在JSON数组中的查询,如下所示。 我想检查一下我的名字是否是约翰,我的爱好是否有运动,但它不起作用

以下类似代码的结果:

[
  {"id":1,"name":"John","hobbies":[{"kind":"sport"},{"kind":"music"}]},
  {"id":5,"name":"John","hobbies":[{"kind":"swimming"},{"kind":"opera"}]}
] 
但它必须是{code>{id:1,“name”:“John”,“cabiods”:[{“kind”:“sport”}{“kind”:“music”}}

function MyCtrl($scope, $filter) {
    $scope.items = [
        {id:1, name:'John',hobbies:[{kind:"sport"},{kind:"music"}]},
        {id:2, name:'Steve',hobbies:[{kind:"opera"},{kind:"theatre"}]},
        {id:3, name:'Joey'},
        {id:4, name:'Mary'},
        {id:5, name:'John',hobbies:[{kind:"swimming"},{kind:"opera"}]}];
    $scope.filteredData = $filter('filter')($scope.items, {name:'John',hobbies:[{kind:''}]});
    $scope.json=JSON.stringify($scope.filteredData);
    // $scope.json2=JSON.stringify($scope.y);
};

1.3.8版支持这种过滤器


(功能(){
angular.module(“myapp”、[]).controller('MainCtrl'、['$scope'、'$filter',函数($scope,$filter){
$scope.items=[
{id:1,名字:'John',爱好:[{kind:'spor},{kind:'music}]},
{id:2,姓名:'Steve',爱好:[{kind:'opera},{kind:'theatre}]},
{id:3,姓名:'Joey'},
{id:4,姓名:'Mary'},
{id:5,姓名:'John',爱好:[{kind:“游泳”},{kind:“歌剧”}]}
];    
$scope.filteredata=$filter('filter')($scope.items,
{姓名:'约翰',爱好:[{种类:'游泳'}]}
);
}]);
}());
{{Filteredata}}

谢谢你。是的,您是对的,1.3.8支持该功能,但当我尝试使用该功能时,1.5.3不起作用:(