【发布时间】:2018-07-28 14:48:58
【问题描述】:
我有一个表格来显示其中的数据,如下图所示。我能想象到的最好的方法是创建一个 3D 数组来用 ng-repeat 显示它,因此没有像我这样的问题来显示它,这样我就可以认为它是不可能的。
我已经尝试过,但没有任何精确的结果,即使我可以在下面的 sn-p 中使用 2D 数组做类似的事情。
var app = angular.module('plunker', []);
app.controller('MainCtrl', function($scope) {
$scope.grid = [
[
["June"],
["July"],
["August"],
["September"]
],
[
["0,1"],
["1,1"],
["4,5"],
["2,1"]
]
[
["3,2"],
["1,0"],
["6,3"],
["2,9"]
]
];
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.4/angular.min.js"></script>
<body ng-app="plunker">
<div ng-controller="MainCtrl">
<table>
<thead>
<tr>
<td></td>
<th class="text-center" colspan="3">Install</th>
<th class="text-center" colspan="3">Uninstall</th>
</tr>
<tr>
<td></td>
<th>AppName1</th>
<th>AppName2</th>
<th>TOTAL</th>
<th>AppName1</th>
<th>AppName2</th>
<th>TOTAL</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="y in grid">
<td ng-repeat="x in y">{{x}}</td>
<td ng-repeat="x in y">{{x[0]}}</td>
</tr>
</tbody>
</table>
</div>
</body>
或者我还在玩plunkr here。
【问题讨论】:
标签: javascript angularjs multidimensional-array angularjs-ng-repeat