<!-- 1 <!DOCTYPE html>
2 <html lang="en">
3 <head>
4 <meta charset="UTF-8">
5 <title>Document</title>
6 <script type="text/javascript" src="../src/angular.min.js"></script>
7 </head>
8 <body ng-app="orderby">
9 <div ng-controller = 'orderby1'>
10
11 <ul>
12 <li style="font-weight:bold;color:#f00">
13 <span>name</span>
14 <span>age</span>
15 <span>sex</span>
16 </li>
17 <li ng-repeat="ss in data | my_filter : 1 | upperCase" >//这两个自定义过滤器每个返回的都是一个数组,这个数组就是和前面的data进行过滤的或者说和data进行匹配
18 <span>{{ss.name }}</span>
19 <span>{{ss.age }}</span>
20 <span>{{ss.sex}}</span>
21 </li>
22 </ul>
23 </div>
24
25
26 <script type="text/javascript">
27 var order = angular.module('orderby' , []);
28 order.controller('orderby1',['$scope' , function($scope){
29 $scope.data = [
30 {name : 'aa', age : '20', sex : '男'},
31 {name : 'ab', age : '30', sex : '女'},
32 {name : 'ba', age : '24', sex : '男'},
33 {name : 'ca', age : '32', sex : '男'},
34 {name : 'da', age : '23', sex : '女'},
35 {name : 'ea', age : '15', sex : '女'},
36 {name : 'ee', age : '25', sex : '男'}
37 ];
38 }]);
39
40 order.filter('my_filter' , function(){
41 return function(e , type){
42 var arr = [];
43 var sexx = type ? '男' : '女';
44 for(var i= 0;i < e.length; i++){
45 if(e[i].age > 20 && e[i].age < 30 && e[i].sex == sexx){
46 arr.push(e[i]);//这里push的是整个e[i]-而不是e[i].age 后面要显示第i条的数据 不是单单显示age
47
48 };
49 };
50 console.log(arr)
51 return arr;
52 };
53 });
54 order.filter('upperCase' , function(){//首字母大写过滤器
55 return function(e){
56 var arr= [];
57 var list = {};
58 for(var i = 0; i < e.length; i ++){
59 list = e[i];
60 list.name = e[i].name.slice(0,1).toUpperCase() +e[i].name.slice(1) ;
61 arr.push(list)
62 }
63 return arr;
64 };
65 })
66 </script>
67 </body>
68 </html> -->