2016-07-18 7 views
2

で複数のテーブルを作成するために、私は、JSONデータネストされたNG-繰り返し異なるデータ

[{"ID": "01000", "Name" : "Name1", "Age" : 25}, 
{"ID": "01001", "Name" : "Name2", "Age" : 30}, 
{"ID": "01001", "Name" : "Name3", "Age" : 23}] 

を持っているとngのリピートを使用して、複数の表に、このデータを表示したいです。表は、この

How the tables should look like

のようになります。私は、「$ scope.ID」変数に個別IDを見つけ機能を作成しました。

$scope.ID = []; 
    $scope.ID.push("1"); 
    var s = 0; 
    for (var i = 0; i < $scope.Report.length; i++){ 

     if ($scope.ID[s] != $scope.Report[i].Id){ 
      $scope.ID.push($scope.Report[i].Id);     
      s++; 
     }    
    } 

その後、私は

<div class="table" ng-repeat="id in ID" ng-model="query"> 

    <div class="row header"> 
     <div class="cell"> 
     ID 
     </div> 
     <div class="cell"> 
     NAME 
     </div> 
     <div class="cell"> 
     AGE 
     </div> 
    </div> 

    <div class="row" ng-repeat="r in Report | filter: query track by $index"> 
     <div class="cell"> 
     {{r.id}} 
     </div> 
     <div class="cell"> 
     {{r.name}} 
     </div> 
     <div class="cell"> 
     {{r.age}} 
     </div> 

    </div> 
    </div> 

このようにテーブルにデータを表示しようとしているスクリプトは、二つのテーブルを返しますが、各テーブルには、同じ3つの値、

What the tables actually look like

を持っています私はそれぞれのテーブルが独自のフィルタ値を持っている必要があります。この場合、最初のテーブルはID:01000と2番目のテーブルでフィルタリングする必要があります。ID:01001.

どうすればいいですか?

答えて

2

試してみてください。

<div class="row header"> 
    <div class="cell"> 
    ID 
    </div> 
    <div class="cell"> 
    NAME 
    </div> 
    <div class="cell"> 
    AGE 
    </div> 
</div> 


<div class="row" ng-repeat="r in Report | filter: {id: id}"> 
    <div class="cell"> 
    {{r.id}} 
    </div> 
    <div class="cell"> 
    {{r.name}} 
    </div> 
    <div class="cell"> 
    {{r.age}} 
    </div> 

</div> 

関連する問題