ng-repeat values with 3 columns in table? - AngularJS

耗尽温柔 提交于 2019-12-25 01:05:22

问题


I'm trying to display data in 3 column table format.

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>

and

    lvar app = angular.module('myApp', []);

app.controller('myCtrl', function ($scope) {
    $scope.array = ["opt1","opt2","opt3","opt4","opt5","opt6","opt7"];
});

Fiddle: http://jsfiddle.net/JG3A5/

I tried but with ng-repeat I'm not able to achieve it properly. Can someone help me out with this?


回答1:


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"]
];

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>

Demo: http://jsfiddle.net/JG3A5/75/



来源:https://stackoverflow.com/questions/29609748/ng-repeat-values-with-3-columns-in-table-angularjs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!