我从网格中获得了这段HTML代码。我需要为依分数值而定的每一行显示不同的颜色,好像它从0到4会是绿色,从5到7会是黄色,从8到10会是红色。
我计划将“ tableColor”变量更改为值:{success,warning,danger}(取决于得分)。我只是不知道如何使用ng-repeat
指令
<tbody>
<tr class="{{tableColor}}" ng-repeat="firm in device.firmwares">
<td>{{firm.fileName}}</td>
<td>{{firm.extracted}}</td>
<td>{{firm.Score}}</td>
<td>{{firm.date}}</td>
</tr>
</tbody>
如果有人知道该怎么做,我将不胜感激!
最佳答案
尝试这个
var app = angular.module("app",[]);
app.controller("ctrl" , function($scope){
$scope.items = [{"name":"ali","score":2},{"name":"reza","score":4},{"name":"amir","score":5},{"name":"amir","score":7},{"name":"amir","score":5},{"name":"asd","score":10},{"name":"jim","score":8},{"name":"babak","score":6},{"name":"vfrt","score":8},{"name":"cdsa","score":7},{"name":"amir","score":10},{"name":"majid","score":3}];
});
.success{
color:green;
}
.warning{
color:yellow;
}
.danger{
color:red;
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="app" ng-controller="ctrl" class="panel-group" id="accordion">
<table>
<tr ng-repeat="item in items" ng-class="{'success': item.score<= 4,'warning' :5<= item.score,'danger' : 8<=item.score }">
<td>{{item.name}}</td>
<td>{{item.score}}</td>
</tr>
</table>
</div>