正在寻找一种方法让 AngularJS 的 ng-repeat orderBy 过滤器在完成渲染后进行回调......
标记:
<div ng-controller="MyCtrl">
<table>
<thead>
<tr>
<th ng-click="sort('name')">Name:</th>
<th ng-click="sort('age')">Age:</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="item in items | orderBy:sortColumn:reverseSort">
<td>{{item.name}}</td>
<td>{{item.age}}</td>
</tr>
</tbody>
</table>
</div>
JS:
var myApp = angular.module('myApp', []);
function MyCtrl($scope) {
$scope.items = [{
"name": "John",
"age": 25
}, {
"name": "Amy",
"age": 75
}, {
"name": "Sarah",
"age": 12
}, {
"name": "Matt",
"age": 55
}, {
"name": "Xaviour",
"age": 2
}];
$scope.sortColumn = 'name';
$scope.reverseSort = false;
$scope.sort = function (column) {
$scope.sortColumn = column;
$scope.reverseSort = !$scope.reverseSort;
};
$scope.sortRenderFinished = function(){
console.log('Done Rendering!');
//Do something
};
}
如您所见.. 一旦 orderBy 过滤器完成执行并更改表行的顺序,我希望看到类似 $scope.sortRenderFinished() 的内容。
任何帮助将非常感激!:-)