-
Notifications
You must be signed in to change notification settings - Fork 0
/
order.html
70 lines (68 loc) · 2.44 KB
/
order.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
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>变量调节器</title>
<script src="./org/angular.min.js"></script>
<script src="./org/underscore-min.js" ></script>
<link rel="stylesheet" href="./org/bootstrap.min.css">
<link rel="stylesheet" href="./org/font-awesome/css/font-awesome.min.css">
</head>
<body>
<div ng-app="hd" ng-controller="ctrl">
<!--{{data}}
<button ng-click="orderBy()">控制器中使用过滤器</button>-->
<table border="1px" width="60%">
<tr>
<td ng-click="orderBy('id')">编号
<span ng-if="status.id">升序</span>
<span ng-if="!status.id">降序</span>
</td>
<td ng-click="orderBy('click')">点击数
<span ng-if="status.click">升序</span>
<span ng-if="!status.click">降序</span>
</td>
<td ng-click="orderBy('title')">标题
<span ng-if="status.title">升序</span>
<span ng-if="!status.title">降序</span>
</td>
</tr>
<tr ng-repeat="(k, v) in data">
<td>{{v.id}}</td>
<td>{{v.click}}</td>
<td>{{v.title}}</td>
</tr>
</table>
</div>
<script>
var m = angular.module('hd', []);
m.controller('ctrl', ['$scope', '$filter', function ($scope, $filter) {
$scope.data = [
{id:1,click:100,title:'后断网'},
{id:2,click:324,title:'那么好'},
{id:3,click:250,title:'你们好'}
];
// $scope.orderBy = function() {
// $scope.data= $filter('orderBy')($scope.data, 'id', true)
// }
// 方法一排序
// $scope.orderBy = function (field) {
// alert(field)
// if(arguments.callee[field] == undefined) {
// arguments.callee[field] = false
// }
// arguments.callee[field] = !arguments.callee[field];
// alert(arguments.callee[field])
// $scope.data = $filter('orderBy')($scope.data, field,true)
// $scope.data = $filter('orderBy')($scope.data, field, arguments.callee[field]);
// }
// 方法二排序
$scope.status = {id: false, click: false, title: false}
$scope.orderBy = function (field) {
$scope.status[field] = !$scope.status[field]
$scope.data = $filter('orderBy')($scope.data, field,$scope.status[field])
}
}]);
</script>
</body>
</html>