gpt4 book ai didi

javascript - 如何使用 AngularJS 添加不同的背景颜色

转载 作者:行者123 更新时间:2023-11-30 15:36:43 24 4
gpt4 key购买 nike

我想为表格设计格式中的 Angular ng-repeat 提供不同的背景颜色。如果 play_id 相同,我想在 tr 标签中提供相同的背景颜色,否则另一种颜色 tr 标签。

JSON ( https://jsfiddle.net/0sasz78n/ )

{
"play_details": [
{
"play_id": "15",
"quest_id": "63",
"question": "What will be the match result ?"
},
{
"play_id": "8",
"quest_id": "61",
"question": "Which of this batswan will score higher ?"
},
{
"play_id": "8",
"quest_id": "59",
"question": "What will be the match result ?"
}
]
}

HTML代码:

<table><tr ng-repeat="single_Play in all_Play_details">
<td>{{$index + 1}}</td>
<td>{{single_Play.play_id}}</td>
<td>{{single_Play.quest_id}}</td>
<td>{{single_Play.question}}</td>
</tr></table>

JS代码:

$scope.all_Play_details = response.data.play_details;

最佳答案

编辑:好的,Rouk 更快;)

我建议使用 ng-class 并在你的 ng-repeat 标签中添加类似下面的内容。

ng-class="{'highlightedCell' : play_details.play_id == currentID, 'diffentColoredCell' : play_details.play_id != currentID"}

当然还要创建适当的 css 类。

关于javascript - 如何使用 AngularJS 添加不同的背景颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41425358/

24 4 0
文章推荐: javascript - 我们可以在类中定义的 redux Action Creators 上使用 bindActionCreators() 吗?
文章推荐: javascript-在ajax调用中显示加载器并在成功后隐藏
文章推荐: javascript - 如何将选中的复选框数据附加到html
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com