如下所示:
<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="external nofollow" 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, name: "魏國", country: "張遼" ,age: 34}, { seq: 3, name: "魏國", country: "司馬懿" ,age: 36 }, { seq: 4, name: "魏國", country: "夏侯淳",age: 40 }, { seq: 5, name: "蜀國", country: "劉備",age: 50 }, { seq: 6, name: "蜀國", country: "關羽",age: 45 }, { seq: 7, name: "蜀國", country: "張飛",age: 46 }, { seq: 8, name: "蜀國", country: "趙云",age: 35 }, { seq: 9, name: "吳國", country: "孫權" ,age: 30 }, { seq: 10, name: "吳國", country: "周瑜",age: 32 }, { seq: 11, name: "吳國", country: "魯肅",age: 33 }, { seq: 12, name: "吳國", country: "黃蓋",age: 55 } ]; $scope.cls = function(i) { return (i + 1) % 4 == 1 ? "active" : ""; } } </script> </body> </html>
效果:
以上這篇angular.js實現列表orderby排序的方法就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持腳本之家。
聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com