AngularJS的ng-repeat显示表格

代码下载:https://files.cnblogs.com/files/xiandedanteng/angualrJSngRepeatTable.rar

代码:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html ng-app="notesApp">
 <head>
  <title> New Document </title>
  <style>
    .odd{
        background-color:red;
        width:400px;
    }
    .even{
        background-color:#336699;
        width:400px;
    }
  </style>
    <meta charset="utf-8">
    <script src="angular1.4.6.min.js"></script>
 </head>

 <body> 
    <table ng-controller="MainCtrl as ctrl">
        <tr ng-repeat="(author,member) in ctrl.members" ng-class="ctrl.getBackground({{$odd}})">
            <td>{{$index}}</td>
            <td><span ng-bind='author'/></td>
            <td><span ng-bind='member.id'/></td>            
            <td><span ng-bind='member.gender'/></td>
            <td><span ng-bind='member.age'/></td>
        </tr>
    </table>
 </body>
</html>
<script type="text/javascript">
<!--
    angular.module('notesApp',[])
     .controller('MainCtrl',[function(){
       var self=this;

       self.members={
        andy:{id:11,age:20,gender:'male'},
        bill:{id:12,age:21,gender:'female'},
        Cindy:{id:23,age:22,gender:'male'},
        douglas:{id:54,age:23,gender:'female'},
        Einstein:{id:85,age:24,gender:'male'},
       };
       
       // 根据奇偶行决定背景
       self.getBackground=function(odd){
            if(odd==true){
                return 'odd';
            }else{
                return 'even';
            }
       };

       
     }]);
//-->
</script>

效果:

转载于:https://www.cnblogs.com/xiandedanteng/p/7414509.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值