我有一个表,我需要从angularjs中的json下面获取数据,在该表中,当我检查inspect元素时,我需要从<tr>
<table>
中的json动态获取“id” 。
这个“id”应该来自下面的json“id”属性。如果“id”重复,那么重复的“id”应该随<tr>
及其数据一起出现。我能够获取json数据但不能动态获取“id”。
<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 :(得分: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>