💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、豆包、星火、月之暗面及文生图、文生视频 广告
思路:导入$filter服务,使用$filter中的orderBy 结合arguments.callee:不会释放,是一个对象,相当于php中的static ![](https://box.kancloud.cn/b5ca5ef0d803437dadde54e12e17a375_779x177.png) <body ng-app="model"> <div ng-controller="a"> <table border="1" width="600"> <tr> <td><button ng-click="orderBy('id')">ID</button></td> <td><button ng-click="orderBy('username')">用户名</button></td> <td><button ng-click="orderBy('age')">年龄</button></td> </tr> <tr ng-repeat="v in data"> <td>{{v.id}}</td> <td>{{v.username}}</td> <td>{{v.age}}</td> </tr> </table> </div> ~~~ <script> var a = angular.module('model', []); a.controller('a', ['$scope', '$filter', function ($scope, $filter) { $scope.data = [ {id: 1, username: 'iooni', age: 22, status: 1}, {id: 2, username: 'iyyan', age: 32, status: 0}, {id: 3, username: 'ccczc', age: 11, status: 1}]; $scope.orderBy = function (filed) { if(arguments.callee[filed]==undefined){ arguments.callee[filed] = false; } arguments.callee[filed] = !arguments.callee[filed]; $scope.data = $filter('orderBy')($scope.data, filed, arguments.callee[filed]); } }]); </script> ~~~