【发布时间】:2017-01-02 19:21:10
【问题描述】:
我想为表格设计格式中的角度 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;
【问题讨论】:
-
您的
jsfiddle链接没有任何内容。 -
{"play_details":[{"play_id":"8","quest_id":"61","question":"哪个蝙蝠侠得分更高?"},{"play_id ":"8","quest_id":"59","question":"比赛结果是什么?"}]}
-
这是json格式
-
您可以使用
ng-style/ng-class,但在此之前,请在数组的每个元素中包含backgroundColor属性 -
play_id会随机变化,那么如何提供ng-class
标签: javascript jquery html css angularjs