gpt4 book ai didi

javascript - 验证 $index 并设置样式

转载 作者:行者123 更新时间:2023-12-03 06:26:13 24 4
gpt4 key购买 nike

我试图突出显示表格行,但很难将其转换为指令内的 Angular js。检查伪代码:

if(highlight.indexOf($index) != -1) set .highlight css class

这是我的代码示例:

$scope.highlight  = [0,2,3]
.highlight {
color: red;
}
<table class="ui celled table">
<thead>
<tr>
<th>AAA</th>
<th>BBB</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="a in as track by $index"> <!-- The ng-class needs to be here, but where should i do the verification? -->
<td>{{a}}</td>
<td>{{b[$index]}}</td>
</tr>
</tbody>
</table>

最佳答案

使用ng-classng-repeat之后:

<tr ng-repeat="a in as track by $index" ng-class="{highlight: highlight.indexOf($index) > -1}">

关于javascript - 验证 $index 并设置样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38646085/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com