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

    ng-repeat 指令可以完美的显示表格。

    在表格中显示数据

    使用 angular 显示表格是非常简单的:

    Customers_JSON.json

    {
        "records": [
            {
                "Name": "Alfreds Futterkiste",
                "City": "Berlin",
                "Country": "Germany"
            }, {
                "Name": "Ana Trujillo Emparedados y helados",
                "City": "México D.F.",
                "Country": "Mexico"
            }, {
                "Name": "Antonio Moreno Taquería",
                "City": "México D.F.",
                "Country": "Mexico"
            }, {
                "Name": "Around the Horn",
                "City": "London",
                "Country": "UK"
            }, {
                "Name": "B's Beverages",
                "City": "London",
                "Country": "UK"
            }, {
                "Name": "Berglunds snabbköp",
                "City": "Luleå",
                "Country": "Sweden"
            }, {
                "Name": "Blauer See Delikatessen",
                "City": "Mannheim",
                "Country": "Germany"
            }, {
                "Name": "Blondel père et fils",
                "City": "Strasbourg",
                "Country": "France"
            }, {
                "Name": "Bólido Comidas preparadas",
                "City": "Madrid",
                "Country": "Spain"
            }, {
                "Name": "Bon app'",
                "City": "Marseille",
                "Country": "France"
            }, {
                "Name": "Bottom-Dollar Marketse",
                "City": "Tsawassen",
                "Country": "Canada"
            }, {
                "Name": "Cactus Comidas para llevar",
                "City": "Buenos Aires",
                "Country": "Argentina"
            }, {
                "Name": "Centro comercial Moctezuma",
                "City": "México D.F.",
                "Country": "Mexico"
            }, {
                "Name": "Chop-suey Chinese",
                "City": "Bern",
                "Country": "Switzerland"
            }, {
                "Name": "Comércio Mineiro",
                "City": "São Paulo",
                "Country": "Brazil"
            }
        ]
    }
    <!DOCTYPE html>
    <html>
        <head>
            <meta charset="utf-8">
            <script src="http://apps.bdimg.com/libs/angular.js/1.4.6/angular.min.js"></script>
        </head>
        <body>
            <div ng-app="myApp" ng-controller="customersCtrl">
                <table>
                    <tr ng-repeat="x in names"> //ng-repeat写在tr中
                        <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("Customers_JSON.json")
                        .success(function(response) {
                            $scope.names = response.records;
                        });
                });
            </script>
        </body>
    </html>

    使用 CSS 样式

    <style>
    table, td  {
      border: 1px solid grey;
      border-collapse: collapse;
      padding: 5px;
    }
    </style>

    使用 orderBy 过滤器

     <table>
      <tr ng-repeat="x in names | orderBy : 'Country'"> //orderBy是写在ng-repeat指令中的,By大写
        <td>{{ x.Name }}</td>
        <td>{{ x.Country }}</td>
      </tr>
    </table> 

    使用 uppercase 过滤器

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

    显示序号 ($index)

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

    使用 $even 和 $odd

                <table>
                    <tr ng-repeat="x in names">
                        <td ng-if="$odd" style=" background-color:#f1f1f1 "> //ng-if 指令不同于 ng-hide, ng-hide 隐藏元素,而 ng-if 是从 DOM 中移除元素。
                            {{$index+1}}</td>
                        <td ng-if="$even ">
                            {{$index+1}}</td>
                        <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>
  • 相关阅读:
    Golang 单例模式 singleton pattern
    golang可见性规则(公有与私有,访问权限)
    golang init方法和main方法初始化顺序
    Golang的面向对象编程【结构体、方法、继承、接口】
    Convert Sorted List to Binary Search Tree——将链表转换为平衡二叉搜索树 &&convert-sorted-array-to-binary-search-tree——将数列转换为bst
    C/C++程序到内存分配(转)
    有关C/C++指针的经典面试题(转)
    C结构体之位域(位段)(转)
    Balanced Binary Tree——数是否是平衡,即任意节点左右字数高度差不超过1
    Path SumI、II——给出一个数,从根到子的和等于它
  • 原文地址:https://www.cnblogs.com/chrisghb8812/p/5664515.html
Copyright © 2011-2022 走看看