angular过滤器实现排序功能

首先定义一个json文件:

angular过滤器实现排序功能

然后写HTML文件:

<div> <!--第一个下拉框--> <select ng-model="a"> <option value="age">按照年龄排序</option> <option value="code">按照编码排序</option> <option value="name">按照姓名排序</option> </select> <!--升序还是降序--> <select ng-model="b"> <option value="">升序</option> <option value="-">降序</option> </select> <!--一个搜索框--> <input type="text" placeholder="请输入要搜索的内容" ng-model="c"/> </div> <!--渲染的数据--> <div> <table> <tr> <th>编码</th> <th>姓名</th> <th>年龄</th> </tr> <tr ng-repeat="item in data|filter:c|orderBy:b+a"> <td>{{item.code}}</td> <td>{{item.name}}</td> <td>{{item.age}}</td> </tr> </table> </div>

angular:

<script> var app = angular.module("mk",[]); app.controller("test",function($scope,$http){ $http.get('json/index.json').success(function(data){ $scope.data = eval(data); $scope.a = "code"; }) }) </script>

在这种运用到的过滤器有filter 、orderBy

这样就完成了一个简单的排序,希望能帮到大家!

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wyfxfz.html