2017-01-30 81 views
0

我嵌套了json數組,其中我需要組合一些值。我無法獲取嵌套標籤進行分組。Angularjs:使用ng-repeat與groupBy訪問嵌套的json數組值

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

如果我是分組「身份證」的工作。如果我的分組「cash.amount」它不工作

誰能幫我解決這個問題呢?

回答

0

你可以做,

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

DEMO

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>