加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angularjs – 在表中的行上使用ng-repeat和ng-class

发布时间:2020-12-17 09:00:43 所属栏目:安全 来源:网络整理
导读:我使用AngularJS和我想得到的效果将是类似于这将产生,假设它将工作(它不会)。 视图 tr ng-repeat='person in people' ng-class='rowClass(person)' td.....info about person.../td td.....info about person.../td td.....info about person.../td/tr 控制
我使用AngularJS和我想得到的效果将是类似于这将产生,假设它将工作(它不会)。

视图

<tr ng-repeat='person in people' ng-class='rowClass(person)'>
  <td>.....info about person...</td>
  <td>.....info about person...</td>
  <td>.....info about person...</td>
</tr>

控制器

$scope.rowClass = function(person){
  ...return some value based upon some property of person...
}

我意识到这个代码将无法工作,因为人不能使用ng-class,因为它只能用于每一行内的对象。代码是得到我想要做的事情的想法:ie。我想能够有使用ng-repeat创建的表行,其类也基于一个条件,该条件取决于对行本身的作用域特征的访问,例如。人。我意识到我可以只添加ng-class列,但这是无聊。任何人有更好的想法?

这应该实际工作正常。 person应该在tr元素和它的孩子上可用,因为它们具有相同的范围。

这似乎工作正常对我来说:

<table>
    <tr ng-repeat="person in people" ng-class="rowClass(person)">
        <td>{{ person.name }}</td>
    </tr>
</table>

http://jsfiddle.net/xEyJZ/

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读