基于json数据的angular实现table循环数据显示

基于json数据的angular实现table循环的后台数据(数据是前端给出写死的)显示,很简单,很好用。

直接上代码

<!doctype html>
<html>
<head>
    <title>phone</title>
    <!--设置字符集-->
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
    <!--禁止页面缩放-->
    <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport">
    <!--忽略页面中的数字识别为电话号码-->
    <meta name="format-detection" content="telephone=no" />
    <!--网站开启对web app程序支持-->
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <!--改变顶部状态条的颜色
    <meta name="apple-mobile-web-app-status-bar-style" content="black" />
    -->
    <!--作者信息-->
    <script type="text/javascript" src="http://chantrans.oss-cn-hangzhou.aliyuncs.com/public/js/jquery-1.10.1.min.js"></script>
     <script src="http://apps.bdimg.com/libs/angular.js/1.3.9/angular.min.js"></script> <!--引进angularjs-->
    <style type="text/css">  
    table tr:nth-child(odd){
      background-color: #f1f1f1
    }
    table tr:nth-child(even){
      background-color: #ffffff
    }
    table,td,tr{
      border: 1px solid black;
      border-collapse: collapse;
    }
    </style>
</head>
<body>
   <table ng-app="myApp" ng-controller="mytro">
     <tr>
       <th>姓名</th>
       <th>性别</th>
       <th>年龄</th>
     </tr>
     <tr ng-repeat="x in names">
       <td>{{x.name}}</td>
       <td>{{x.gender}}</td>
       <td>{{x.old}}</td>
     </tr>
   </table>
</body>
   <script type="text/javascript">
    var app = angular.module('myApp', []);
   app.controller('mytro', function($scope) {
      var s='{"student":[{"name":"wangxupeng","gender":"male","old":18},{"name":"wenmenghu","gender":"fema    le"    ,"old":20}]}';
      $scope.names=eval("("+s+")").student;//JSON数据格式方式
      /*var s2=[{name:"wangxupeng",gender:"male",old:18},{name:"wenmenghu",gender:"female",old:20}];
      $scope.names=s2;*/      /*正常数组方式*/
  });
   </script>
</html>

 

转载于:https://www.cnblogs.com/iamwangxupeng/p/5010509.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值