Angularjs:使用ng-repeat和groupBy访问嵌套的json数组值

时间:2017-01-30 05:00:19

标签: angularjs json grouping ng-repeat

我已经嵌套了json数组,其中我需要使用一些值进行分组。我无法获取嵌套标记进行分组。

$scope.sampleTest = [{"id": "1", "cash": {"amount":"4000"}},
                     {"id": "2", "cash": {"amount":"2000"}}]

如果我正在将'id'分组工作,如果我将'cash.amount'分组,那就无法正常工作

有人可以帮我解决这个问题吗?

1 个答案:

答案 0 :(得分:0)

你可以,

<div ng-repeat="record in sampleTest | filter: {cash:{amount:'2000'}}:true ">

<强>样本

var app = angular.module('todoApp', []);

app.controller("dobController", ["$scope",
  function($scope) {
   $scope.sampleTest = [{"id": "1", "cash": {"amount":"4000"}},
                     {"id": "2", "cash": {"amount":"2000"}},
                        {"id": "3", "cash": {"amount":"2000"}}];
 
   
  
  }
]);
<!DOCTYPE html>
<html ng-app="todoApp">

<head>
  <title>Sample</title>
  <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.1/angular.min.js"></script>
</head>
<body ng-controller="dobController">
 <div ng-repeat="record in sampleTest | filter: {cash:{amount:'2000'}}:true ">
     <ul>
       <li >{{ record}}</li>
    </ul>
</div>
 
</body>

</html>