angular.js实现列表orderby排序
发布时间:2020-12-17 10:13:52 所属栏目:安全 来源:网络整理
导读:html ng-app head titleorder by/title meta http-equiv="X-UA-Compatible" content="IE=edge" / meta name="viewport" content="width=device-width,initial-scale=1" / link href="../book/css/bootstrap.css" rel="stylesheet" type="text/css" / script
<html ng-app> <head> <title>order by</title> <meta http-equiv="X-UA-Compatible" content="IE=edge" /> <meta name="viewport" content="width=device-width,initial-scale=1" /> <link href="../book/css/bootstrap.css" rel="stylesheet" type="text/css" /> <script src="../file/angular-1.0.1.min.js" type="text/javascript"></script> </head> <body> <div class="table-responsive" ng-controller="demoController"> <table id="tb" class="table table-bordered table-hover"> <thead> <tr> <th class="col-md-2">编号</th> <th class="col-md-4">国家</th> <th class="col-md-4">名称</th> <th class="col-md-3">年龄</th> </tr> </thead> <tbody id="tbody" ng-repeat="stu in data | orderBy : '-age' | limitTo: 10"> <tr class="{{ cls($index) }}"> <td>{{ $index + 1 }}</td><td>{{ stu.country }}</td><td>{{ stu.name }}</td><td>{{ stu.age }}</td> </tr> </tbody> </table> </div> <script type="text/javascript"> function demoController($scope,$window) { $scope.data = [ { seq: 1,name: "魏国",country: "曹操",age : 45 }, { seq: 2,country: "张辽",age: 34}, { seq: 3,country: "司马懿",age: 36 }, { seq: 4,country: "夏侯淳",age: 40 }, { seq: 5,name: "蜀国",country: "刘备",age: 50 }, { seq: 6,country: "关羽",age: 45 }, { seq: 7,country: "张飞",age: 46 }, { seq: 8,country: "赵云",age: 35 }, { seq: 9,name: "吴国",country: "孙权",age: 30 }, { seq: 10,country: "周瑜",age: 32 }, { seq: 11,country: "鲁肃",age: 33 }, { seq: 12,country: "黄盖",age: 55 } ]; $scope.cls = function(i) { return (i + 1) % 4 == 1 ? "active" : ""; } } </script> </body> </html> 效果:
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |