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>
  • 相关阅读:
    进程、线程、协程
    C++内存模型
    动态库dll与静态库lib
    virtual 虚函数表
    C++面试随笔
    alloc()、malloc()、calloc()、realloc()区别及用法
    C/C++ 面试题记录
    VC底层钩子程序在Win7/Vista下无效
    JMeter安装之后修成中文版
    明天开始 新的旅程
  • 原文地址:https://www.cnblogs.com/cf924823/p/5231192.html
Copyright © 2011-2022 走看看