我正在使用angularjs,并且在更新表格中的某个值时,我想将CSS类添加到特定的单元格中。只使表格中突出显示的单元格值
- 我该如何只添加高亮类也只有该单元格?而不是整行......使用角度指令
预期行为:由于更新了Value2,因此只应突出显示该单元格。
我plunker:http://plnkr.co/edit/mfglNOpluccUKLTlLdja?p=preview
我的表:
<table border="1" style="width: 320px;" class="table table-striped table-hover table-responsive table-bordered">
<thead style="font-weight: bold;">
<tr>
<th ng-repeat="column in columnsTest" ng-if="column.checked" ng-bind="column.id"></th>
</tr>
</thead>
<tbody>
<tr ng-repeat="row in rows">
<td ng-repeat="column in columnsTest" ng-if="column.checked">
<span class="glyphicon glyphicon-circle-arrow-right" ng-show="column.id === 'Value1'"></span>
<span data-highlighter="row.Updated">{{row[column.id]}}</span>
</td>
</tr>
</tbody>
</table>
CSS:
.highlight {
background-color: lightgreen;
transition: background 200ms;
}
角指令:
app.directive('highlighter', ['$timeout', function ($timeout) {
return {
restrict: 'A',
scope: {
model: '=highlighter'
},
link: function (scope, element) {
scope.$watch('model', function(updated) {
if (updated) {
element.addClass('highlight');
// auto remove after some delay
$timeout(function() {
element.removeClass('highlight');
}, 1000);
}
});
}
};
当你说“'row.Updated'得到未定义”时,你是什么意思?是什么让你说,这是怎么一个问题?你的低调看起来像是在按照它应该的方式工作;期望的行为是什么? –
对不起,不清楚。我预期的行为是只有一个单元格应该突出显示,而不是整行 – MrProgram