表中有3列的ng-repeat值? - AngularJS [英] ng-repeat values with 3 columns in table? - AngularJS
本文介绍了表中有3列的ng-repeat值? - AngularJS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试以3列表格格式显示数据。
I'm trying to display data in 3 column table format.
使用以下代码我可以获得3列格式的数据,但我想要它正确table,with tr和td。
With the below code am able to get data in 3 column format but I want it in proper table, with tr and td.
<body ng:app="myApp" ng:controller="myCtrl">
<span ng:repeat="(index, value) in array">
{{value}}<br ng:show="(index+1)%3==0" />
</span>
</body>
和
lvar app = angular.module('myApp', []);
app.controller('myCtrl', function ($scope) {
$scope.array = ["opt1","opt2","opt3","opt4","opt5","opt6","opt7"];
});
小提琴: http://jsfiddle.net/JG3A5/
我试过但是用ng-repeat我无法正确实现它。有人可以帮我解决这个问题吗?
I tried but with ng-repeat I'm not able to achieve it properly. Can someone help me out with this?
推荐答案
如果你可以改变你的数据格式,那肯定会更容易数组数组,每个内部数组代表一行:
If you can change your data format, it'd certainly be easier to have an array of arrays, each inner array representing a row:
$scope.data = [
["opt1", "opt2", "opt3"],
["opt1", "opt2", "opt3"],
["opt1", "opt2", "opt3"]
];
然后你可以做一个简单的内部 ng-repeat
You could then do a simple inner ng-repeat
<table>
<tr ng-repeat="row in data">
<td ng-repeat="column in row">{{column}}</td>
</tr>
</table>
演示: http://jsfiddle.net/JG3A5/75/
这篇关于表中有3列的ng-repeat值? - AngularJS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文