我的json中有数据,它将是动态的,我希望在一个包含两列的表中显示数据。我正在尝试,但只有前两张唱片在重复。我没有看到桌子上所有的记录。有什么帮助吗?
http://plnkr.co/edit/Hnb7hkjA16XDbzRT8VAt?p=preview
This is my json : var data = '{
"output":{
"service-status":[
{
"service":"db",
"service-name":"Mongo DB"
},
{
"service":"license",
"service-name":"Smart License"
},
{
"service":"BRM",
"service-name":"Billing"
},
{
"service":"subscription",
"service-name":"subscription"
}
]
}
}';我的html代码:
<table border="1px" width="100%" ng-repeat="data in serviceData" ng-if="$index % 2 == 0">
<tr>
<td>{{serviceData[index]["service-name"]}}</td>
</tr>
</table>
i want to display something like this
Mongo Db Smart License
Billing subscription发布于 2016-06-10 18:01:30
在控制器中转换数据:
var serviceDataView = function() {
var res = [];
for (var i = 0; i < $scope.serviceData.length; i+=2){
res.push({
col1: $scope.serviceData[i]['service-name'],
col2: $scope.serviceData[i+1] ? $scope.serviceData[i+1]['service-name'] : null
});
}
return res;
};
$scope.structuredData = serviceDataView();因此它可以很容易地在视图中使用:
<table border="1px" width="100%">
<tr ng-repeat="data in structuredData">
<td>{{data.col1}}</td>
<td>{{data.col2}}</td>
</tr>
</table>柱塞。
发布于 2016-06-10 18:25:33
使用ng重复的迭代器是$index。
其他编辑:https://docs.angularjs.org/api/ng/directive/ngRepeat
将您的桌子替换为:
<table border="1px" width="100%" ng-repeat="data in serviceData">
<tr>
<td>{{serviceData[$index]["service"]}}</td>
<td>{{serviceData[$index]["service-name"]}}</td>
</tr>
</table>发布于 2016-06-11 07:07:55
根据我的评论,这个问题根本不需要$index。您可以为表ngRepeat.check使用筛选器--此链接
html code here:
<table border="1px" width="100%" ng-repeat="data in serviceData |limitTo:2 ">
<tr>
<td>{{data["service-name"]}}</td>
<td>{{data.service}}</td>
</tr>
https://stackoverflow.com/questions/37754397
复制相似问题