我正在尝试在给定的方阵$scope.matrix
中为对角线着色。
<table>
<tr ng-repeat="row in matrix track by $index">
<td>{{matrix[$index].title}}</td>
<td>{{$index+1}}</th> <!-- # on left side of table as info -->
<td ng-repeat="column in row track by $index">{{column.itemData}}</td>
</tr>
</table>
插入开头的两列信息。 因此输出应为:
+------+------+------+------+------+
| Col1 | Col2 | ColA | ColB | ColC |
| dim | 1 | x | | |
| dim | 2 | | x | |
| dim | 3 | | | x |
+------+------+------+------+------+
'x'标记的细胞着色。我不知道如何使用$index
或ng-repeat来做到这一点。它的荒谬但我不知道如何。
有什么建议吗?
答案 0 :(得分:1)
试试这个
<tr ng-repeat="(key, row) in matrix track by $index">
<td>{{matrix[$index].title}}</td>
<td>{{$index+1}}</th> <!-- # on left side of table as info -->
<td ng-class="{'class-name': key == $index}" ng-repeat="column in row track by $index">{{column.itemData}}</td>
</tr>
CSS
.class-name{
color:red;
}