在2d阵列角度矩阵中着色对角线

时间:2016-05-06 05:46:49

标签: angularjs matrix multidimensional-array html-table

我正在尝试在给定的方阵$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来做到这一点。它的荒谬但我不知道如何。 有什么建议吗?

1 个答案:

答案 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;
}