我有一个数组数组(表示行和列),我需要使用数据呈现HTML表。
每一行都是一列列值,例如:$scope.table.row[0] = [123, 456, 789]
这是我的尝试(不起作用)。有什么想法吗?
<table>
<tbody>
<tr ng-repeat="row in table">
<td ng-repeat="col in row">{{col}}</td>
</tr>
</tbody>
</table>
答案 0 :(得分:6)
您需要迭代table
或使<table>
<tbody>
<tr ng-repeat="row in table.row">
<td ng-repeat="col in row">{{col}}</td>
</tr>
</tbody>
</table>
数组本身。 Demo
table = [ [123, 456, 789], [111, 222, 333], [111, 222, 333]]
<table>
<tbody>
<tr ng-repeat="row in table">
<td ng-repeat="col in row">{{col}}</td>
</tr>
</tbody>
</table>
OR
{{1}}
答案 1 :(得分:1)
您还可以像这样使用*ngFor
:
rows = [['a1','a2', 'a3'],['b1','b2', 'b3'],['c1','c2', 'c3']]'
<table>
<tbody>
<tr *ngFor="let row of rows">
<td *ngFor="let item of row">
{{ item }}
</td>
</tr>
</tbody>
</table>
结果:
a1 a2 a3
b1 b2 b3
c1 c2 c3