2017-06-12 62 views
0

我有一個表,我需要從angularjs中獲取json的數據,在該表中,當我檢查檢查元素時,我需要動態地從json中獲取「id」。 這個「id」應該來自下面的json「id」屬性。如果「id」重複,那麼重複的「id」應該與他們的數據一起出現。我能夠獲取json數據,但沒有動態獲取「id」。動態genarating表與JSON內容

<table id="example" class="display spacing-table" cellspacing="0" width="100%" > 
     <thead style="display:none;"> 
      <tr> 
       <th>sample</th> 
       <th>sample</th> 
       <th>sample</th> 

      </tr> 
     </thead > 



     <tbody> 
     <tr ng-repeat="x in names" ng-show="show=={{$index}}"> 
     <td><img src="images/Project-icon.png">{{x.Name}}</td> 
     <td>{{x.City}}</td> 
     <td>{{x.Country}}</td> 
     </tr> 


     </tbody> 
    </table> 

angular.module('TabsApp', []) 
.controller('TabsCtrl', ['$scope', function ($scope) { 

    $scope.show = 1; 
    //alert('hi'); 
    $scope.names =[ 
    { 
    "Name" : "Max Joe", 
    "City" : "Lulea", 
    "Country" : "Sweden", 
    "id":"1" 
    }, 
    { 
    "Name" : "Manish", 
    "City" : "Delhi", 
    "Country" : "India", 
    "id":"2" 
    }, 
    { 
    "Name" : "Koniglich", 
    "City" : "Barcelona", 
    "Country" : "Spain", 
    "id":"1" 
    }, 
    { 
    "Name" : "Wolski", 
    "City" : "Arhus", 
    "Country" : "Denmark", 
    "id":"3" 
    } 
];  
}]); 
+0

能否請你幫我。 – ankush

回答

0

正確答案

<tr ng-repeat="x in names" ng-show="show=={{x.id}}"> 
     <td><img src="images/Project-icon.png">{{x.Name}}</td> 
     <td>{{x.City}}</td> 
     <td>{{x.Country}}</td> 
     </tr>