我想使用angularJS
orderby filter 来复选框以及按列排序。这对我来说很好:
<tr ng-repeat="player in players | orderBy:'id':true | rangeFilter:min:max">
<td>{{player.id}}</td>
</tr>
我想通过复选框确定orderby
。我该怎么做?
<input type="checkbox"> Order by id
答案 0 :(得分:1)
可能对你有帮助。
var myapp = angular.module('app', []);
myapp.controller('Main', function ($scope) {
$scope.model = false;
$scope.data =[
{
"content" : "some content0",
"createdAt" : "1459401001460",
"completed" : false
},
{
"content" : "some content1",
"createdAt" : "1459401001325",
"completed" : true
},
{
"content" : "some content2",
"createdAt" : "1459401001460",
"completed" : false
},
{
"content" : "some content3",
"createdAt" : "1459401001325",
"completed" : true
},
{
"content" : "some content4",
"createdAt" : "1459401001460",
"completed" : false
},
{
"content" : "some content5",
"createdAt" : "1459401001325",
"completed" : true
}
];
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app = "app">
<div ng-controller="Main">
<input type="checkbox" ng-model="model">
<div >
<table class="table table-bordered">
<tr ng-repeat="d in data | filter: {completed: model }">
<td>{{d.content}}</td>
</tr>
</table>
</div>
</div>
</div>