orderBy排序与挑选的例子

2)
<!DOCTYPE html>
<html ng-app=”filterApp”>

<head>
    <meta charset="UTF-8">
    <title></title>
</head>

<body ng-controller="indexCtrl">
    <input ng-model="search2" />
    <select ng-model="search1">
        <option value="name">name</option>
        <option value="age">age</option>
    </select>
    <button ng-click="sort=!sort">排序</button>
    <ul ng-show="search1=='name'">
        <li ng-repeat="arr in arrs|filter:{name:search2}|orderBy:'name':sort">name:{{arr.name}} age:{{arr.age}}</li>
    </ul>
    <ul ng-show="search1=='age'">
        <li ng-repeat="arr in arrs|filter:{age:search2}|orderBy:'age':sort">name:{{arr.name}} age:{{arr.age}}</li>
    </ul>
    </div>
</body>
<script src="js/angular.js"></script>
<script>
    var app = angular.module('filterApp', []);
    app.controller('indexCtrl', ['$scope', function($scope) {

        $scope.arrs = [{
            name: 'xie',
            age: 30
        }, {
            name: 'lan',
            age: 26
        }, {
            name: 'yao',
            age: 26
        }, {
            name: 'yi',
            age: 18
        }, {
            name: 'ming',
            age: 16
        }];

        $scope.search1 = '';
        $scope.search2 = '';
        $scope.sort = true;

    }])
</script>

</html>

    原文作者:ztvicky
    原文地址: https://segmentfault.com/a/1190000008727823
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞