zoukankan      html  css  js  c++  java
  • AngularJS 表格


    在表格中显示数据

    <div ng-app="myApp" ng-controller="customersCtrl"

    <table >
      <tr ng-repeat="x in names">
        <td>{{ x.Name }}</td>
        <td>{{ x.Country }}</td>
      </tr>
    </table>

    </div>

    <script>
    var app = angular.module('myApp', []);
    app.controller('customersCtrl', function($scope, $http) {
        $http.get("/try/angularjs/data/Customers_JSON.php")
        .success(function (response) {$scope.names = response.records;});
    });

    </script> 

    使用 CSS 样式

    <style>
    table, th , td  {
      border: 1px solid grey;
      border-collapse: collapse;
      padding: 5px;
    }
    table tr:nth-child(odd) {
      background-color: #f1f1f1;
    }
    table tr:nth-child(even) {
      background-color: #ffffff;
    }
    </style>
    </head>
    <body>
    <div ng-app="myApp" ng-controller="customersCtrl"> 
    <table>
      <tr ng-repeat="x in names">
        <td>{{ x.Name }}</td>
        <td>{{ x.Country }}</td>
      </tr>
    </table>
    </div>
    <script>
    var app = angular.module('myApp', []);
    app.controller('customersCtrl', function($scope, $http) {
        $http.get("http://www.runoob.com/try/angularjs/data/Customers_JSON.php")
        .success(function (response) {$scope.names = response.records;});
    });
    </script>

    使用 orderBy 过滤器

    <style>
    table, th , td  {
      border: 1px solid grey;
      border-collapse: collapse;
      padding: 5px;
    }
    table tr:nth-child(odd) {
      background-color: #f1f1f1;
    }
    table tr:nth-child(even) {
      background-color: #ffffff;
    }
    </style>
    </head>
    <body>
    <div ng-app="myApp" ng-controller="customersCtrl"> 
    <table>
      <tr ng-repeat="x in names | orderBy : 'Country'">
        <td>{{ x.Name }}</td>
        <td>{{ x.Country }}</td>
      </tr>
    </table>
    </div>
    <script>
    var app = angular.module('myApp', []);
    app.controller('customersCtrl', function($scope, $http) {
        $http.get("/try/angularjs/data/Customers_JSON.php")
        .success(function (response) {$scope.names = response.records;});
    });
    </script>

     pasting

    显示序号 ($index)

    <style>
    table, th , td  {
      border: 1px solid grey;
      border-collapse: collapse;
      padding: 5px;
    }
    table tr:nth-child(odd) {
      background-color: #f1f1f1;
    }
    table tr:nth-child(even) {
      background-color: #ffffff;
    }
    </style>
    </head>
    <body>
    <div ng-app="myApp" ng-controller="customersCtrl"> 
    <table>
      <tr ng-repeat="x in names">
        <td>{{ $index + 1 }}</td>
        <td>{{ x.Name }}</td>
        <td>{{ x.Country }}</td>
      </tr>
    </table>
    </div>
    <script>
    var app = angular.module('myApp', []);
    app.controller('customersCtrl', function($scope, $http) {
        $http.get("/try/angularjs/data/Customers_JSON.php")
        .success(function (response) {$scope.names = response.records;});
    });
    </script>

    使用 $even(索引为偶数) 和 $odd(索引为奇数)  index从0 开始

    <style>
    table, td  {
      border: 1px solid grey;
      border-collapse: collapse;
      padding: 5px;
    }
    </style>
    </head>
    <body>
    <div ng-app="myApp" ng-controller="customersCtrl"> 
    <table>
      <tr ng-repeat="x in names">
        <td ng-if="$odd" style="background-color:#f1f1f1">
        {{ x.Name }}</td>
        <td ng-if="$even">
        {{ x.Name }}</td>
        <td ng-if="$odd" style="background-color:#f1f1f1">
        {{ x.Country }}</td>
        <td ng-if="$even">
        {{ x.Country }}</td>
      </tr>
    </table>
    </div>
    <script>
    var app = angular.module('myApp', []);
    app.controller('customersCtrl', function($scope, $http) {
        $http.get("/try/angularjs/data/Customers_JSON.php")
        .success(function (response) {$scope.names = response.records;});
    });
    </script>
  • 相关阅读:
    Java transient 关键字
    Android学习资料收集
    mac 关闭&&显示隐藏文件命令
    Android 学习资源收集
    Android Studio 快捷键
    Volley框架使用笔记
    Jni :三维数组处理方法 ,以整形三维数组为例 C++实现
    Git使用- 基本命令
    Jni 调试 : eclipse + Vs 联合调试
    Java 调用 C++ (Java 调用 dll)康哥手把手教你
  • 原文地址:https://www.cnblogs.com/cf924823/p/5231192.html
Copyright © 2011-2022 走看看