Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/15.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 使用Angularjs显示多个相同的JSON键_Javascript_Json_Angularjs_Angularjs Ng Repeat - Fatal编程技术网

Javascript 使用Angularjs显示多个相同的JSON键

Javascript 使用Angularjs显示多个相同的JSON键,javascript,json,angularjs,angularjs-ng-repeat,Javascript,Json,Angularjs,Angularjs Ng Repeat,当我键入Monday并单击Search时,我希望获得所有Monday的JSON数据,而不仅仅是第一行。我尝试过修改forEach函数,并在html中使用了两个ng repeat。我猜是JSON数据结构? . 您需要使用以下代码: angular.forEach($scope.items, function (value, key) { if (key === enteredValue) { angular.forEach(value,

当我键入Monday并单击Search时,我希望获得所有Monday的JSON数据,而不仅仅是第一行。我尝试过修改forEach函数,并在html中使用了两个ng repeat。我猜是JSON数据结构? .


您需要使用以下代码:

angular.forEach($scope.items, function (value, key) {
            if (key === enteredValue) {
                angular.forEach(value, function(item) {
                    $scope.results.push({
                        name: key,
                        address: item.Address,
                        phone: item.Phone, 
                        status: item.Status
                    });
                });

            }
        });
问题是你只使用了一个forEach,而实际上你需要两个forEach。您的数据结构没有问题

但是,您也可以这样做:

    angular.forEach($scope.items[enteredValue], function (item, key) {
           $scope.results.push({
                    name: enteredValue,
                    address: item.Address,
                    phone: item.Phone, 
                    status: item.Status
                });

    });
这就更简单了。我希望这有帮助

谢谢。
    angular.forEach($scope.items[enteredValue], function (item, key) {
           $scope.results.push({
                    name: enteredValue,
                    address: item.Address,
                    phone: item.Phone, 
                    status: item.Status
                });

    });