我想用不同的颜色来区分这些值。这是我想要做的一个粗略的想法。我能够为按钮做到这一点,但不能在表格中做到这一点。从数据库中检索值时,我想根据 diary.level 值放置背景颜色。
健康.js
angular
.module('app')
.controller('TrackingController', ['$scope', 'Diary', '$state', function($scope, Diary, $state) {
$scope.diaries = [];
$scope.submitForm = function() {
Diary
.upsert({
date: $scope.diary.date,
taken: $scope.diary.taken,
level: $scope.diary.level
})
.$promise
.then(function() {
$state.go('data');
});
};
}])
.controller('DataController', ['$scope', 'Diary', function ($scope, Diary) {
$scope.diaries = Diary.find();
if($scope.diary.level == "1-3.8") {
$scope.buttonClass = "background-color:lightgreen";
}
else if ($scope.diary.level == "4-7") {
$scope.buttonClass = "background-color:tomato";
}
else if ($scope.diary.level == "7.2-10.0") {
$scope.buttonClass = "background-color:purple";
}
else {
$scope.buttonClass = "background-color:yellow";
}
}])
数据.html
<section>
<body>
<table style="width:90%" align="center">
<tr>
<th>Date</th>
<th>Type</th>
<th>Level</th>
</tr>
<tr ng-repeat="d in diaries">
<td>{{d.date}}</td>
<td>{{d.taken}}</td>
<td style={{buttonClass}}>{{d.level}}</td>
</tr>
</table>
</body>
</section>