AngularJS中$scope.status(排序例子)

来源:互联网 发布:apache 测试工具 编辑:程序博客网 时间:2024/06/06 08:50
<!DOCTYPE html><html>    <head>        <meta charset="UTF-8">        <title></title>        <script type="text/javascript" src="js/angular.min.js"></script>    </head>    <body ng-app="Mapp" ng-controller="Mctrl">        <table border="1px" cellspacing="0" cellpadding="0">            <tr>                <th ng-click="orderBy('id')">编号</th>                <th>点击数</th>                <th>标题</th>            </tr>            <tr ng-repeat="(k,v) in data">                <td>{{v.id}}</td>                <td>{{v.click}}</td>                <td>{{v.title}}</td>            </tr>        </table>        <script>            var m = angular.module("Mapp", [])                m.controller("Mctrl", function($scope,$filter) {                    $scope.data = [{                        id: 1,                        click: 100,                        title: '罗马'                    },{                        id: 2,                        click: 200,                        title: '伊利'                    },{                        id: 3,                        click: 300,                        title: '阿富汗'                    }];                    $scope.status={id:false,click:false,title:false};                    $scope.orderBy = function(field){                        $scope.status[field]=!$scope.status[field];                        alert($scope.status[field])                        $scope.data = $filter("orderBy")($scope.data,field,$scope.status[field])                    }                })        </script>    </body></html>