This repository has been archived by the owner on Jun 8, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 45
/
filter.html
71 lines (67 loc) · 2.24 KB
/
filter.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<!DOCTYPE html>
<html ng-app="myApp">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
<title>Filter - AngularJS Test</title>
<style type="text/css">
.test-div {margin:15px;padding:15px;border:1px solid #ccc;}
table {table-layout:fixed;border-collapse:collapse;width:600px;}
th, td {padding:5px;border:1px solid #ccc;}
th {background-color:#CAD2D3;cursor:pointer;}
</style>
</head>
<body>
<div class="test-div" ng-controller="myCtrl">
<h3>点击表头排序</h3>
<table>
<tr>
<th ng-click="orderCol('name')">Name</th>
<th ng-click="orderCol('country')">Country</th>
</tr>
<tr ng-repeat="user in users | orderBy: orderProp">
<td>{{user.name | uppercase}}</td>
<td>{{user.country | myFilter}}</td>
</tr>
</table>
</div>
<script type="text/javascript" src="static/js/angular-1.5.8.js"></script>
<script type="text/javascript">
/**
* Filters can be added in AngularJS to format/transform data:
* filter: Select a subset of items from an array.
* orderBy: Orders an array by an expression.
* limitTo: Limits an array/string, into a specified number of elements/characters.
* json: Format an object to a JSON string.
* date: Format a date to a specified format.
* currency: Format a number to a currency format.
* number: Format a number to a string.
* lowercase: Format a string to lower case.
* uppercase: Format a string to upper case.
*/
var myApp = angular.module("myApp", []);
//自定义Filter
myApp.filter("myFilter", function() {
return function(val) {
return val + "@";
}
});
myApp.controller("myCtrl", function($scope) {
$scope.users = [
{name:'Jani',country:'Norway'},
{name:'Carl',country:'Sweden'},
{name:'Margareth',country:'England'},
{name:'Hege',country:'Norway'},
{name:'Joe',country:'Denmark'},
{name:'Gustav',country:'Sweden'},
{name:'Birgit',country:'Denmark'},
{name:'Mary',country:'England'},
{name:'Kai',country:'Norway'}
];
$scope.orderCol = function(o) {
$scope.orderProp = o;
};
});
</script>
</body>
</html>