2

有没有办法在行或列上添加类取决于值。如果列“anzahl”为空,则行背景颜色必须为“灰色”,列“anzahl”背景颜色变为“红色。

    <body ng-app ng-init='articles = [
   {"id":"1","name":"A&R","type":"P77 ","anzahl":"0"},
   {"id":"2","name":"Accuphase","type":"AC5 ","anzahl":"1"},
   {"id":"3","name":"Acoustical Systems","type":"Archon","anzahl":"1"}
  ]'>
  <div class="container">


    <table class="table">
      <tr ng-repeat="article in articles">
        <td>{{article.name}}</td>
        <td>{{article.type}}</td>
        <td>{{article.anzahl}}</td>
      </tr>
    </table>

  </div>

</body>

jsfiddle

4

2 回答 2

4

您可以ng-class="{'class': expession}"在您的情况下使用

CSS

.custom-class{
  background-color: gray
}

.default-color{
  background-color: red
}


<table class="table">
  <tr ng-repeat="article in articles" ng-class="{'custom-class': article.anzahl == null, 'default-color': article.anzahl != null}">
    <td>{{article.name}}</td>
    <td>{{article.type}}</td>
    <td>{{article.anzahl}}</td>
  </tr>
</table>

谢谢。

于 2015-02-05T06:51:48.727 回答
1

这是我固定的小提琴,它是如何工作的。

.custom-class{
  background-color: gray
}

.default-color{
  background-color: white
}

.warning-class {
  background-color: red  
}


<table class="table">
  <tr ng-repeat="article in articles" ng-class="{'custom-class': article.anzahl === '0', 'default-color': article.anzahl !== '0'}">
    <td>{{article.name}}</td>
    <td>{{article.type}}</td>
    <td ng-class="{'warning-class': article.anzahl === '0', 'default-color': article.anzahl !== '0'}">{{article.anzahl}}</td>
  </tr>
</table>

小提琴

于 2015-02-05T07:17:51.413 回答