<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script type="text/javascript" src="js/angular.min.js"></script>
</head>
<body ng-app="Mapp" ng-controller="Mctrl">
<table border="1px" cellspacing="0" cellpadding="0">
<tr>
<th ng-click="orderBy('id')">编号</th>
<th>点击数</th>
<th>标题</th>
</tr>
<tr ng-repeat="(k,v) in data">
<td>{{v.id}}</td>
<td>{{v.click}}</td>
<td>{{v.title}}</td>
</tr>
</table>
<script>
var m = angular.module("Mapp", [])
m.controller("Mctrl", function($scope,$filter) {
$scope.data = [{
id: 1,
click: 100,
title: '罗马'
},{
id: 2,
click: 200,
title: '伊利'
},{
id: 3,
click: 300,
title: '阿富汗'
}];
$scope.status={id:false,click:false,title:false};
$scope.orderBy = function(field){
$scope.status[field]=!$scope.status[field];
alert($scope.status[field])
$scope.data = $filter("orderBy")($scope.data,field,$scope.status[field])
}
})
</script>
</body>
</html>
AngularJS中$scope.status(排序例子)
最新推荐文章于 2024-08-20 06:30:22 发布