簡體   English   中英

如何根據 angularJs 中的條件突出顯示表格行?

[英]How to highlight table row based on condition in angularJs?

所以我得到了顯示某些數據的表格,其中包括日期和其他內容。 我想要的是突出顯示日期與當天相同的行。 表按日期排序。 關於這個用例的任何想法? 這是我的代碼:

 <table class="table table-striped" style="font-size:14px; margin-left: 5px;">
  <head>
   <tr>
     <th style="text-align: left;"><data-i18n i18n="_m_f_pen_feeding_start_date_">Feeding date</data-i18n></th>
     <th style="text-align: left;"><data-i18n i18n="_m_f_pen_frequency_of_feeding_">Frequency of feeding</data-i18n></th>
            <th></th>
   </tr>
</thead>
    <tbody>
      <tr ng-repeat="freq in vm.details.pen_feeding_scheduler_list | orderBy:'-start_feeding_date'">
       <td style="min-width: 120px; text-align: left;">{{freq.start_feeding_date | date:'shortDate'}}</td>
       <td style="min-width: 120px; text-align: left;  display: inline-block;white-space: nowrap">{{freq.feeding_frequency || ('_label_empty_' | i18n)}}</td>
       </tr>
      </tbody>
     </table>

在我的 controller 中,我將當前日期設置為:

 vm.current_date = new Date().toISOString().slice(0, 10)

如果您需要更多代碼,我可以提供。 提前致謝

這是一個簡單示例的小提琴鏈接。 您可以根據需要對其進行修改。

<div ng-class="getClass()">text</div>

Controller:

var myModule = angular.module('app', []);
var current_date = new Date().toISOString().slice(0, 10);

myModule.controller('myCtrl', function ($scope) {


  $scope.getClass = function(){
        if(current_date == '2020-07-23'){
      return 'blue';
      }else{
      return 'red';
      }
  } 

});

http://jsfiddle.net/5oc3fqzj/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM