我想为表列添加排序功能,但出现此错误:
[orderBy:notarray] Expected array but received: 0
此外,排序根本不起作用。当上下箭头更改位置时,调试器似乎正在获取正确的信息。
我的HTML:
<th class="text-center"><a style="color:black"
ng-click="sortColumn('severity')">
Level
<span ng-show="sortTable('severity')" class="fa fa-caret-down"></span>
<span ng-show="sortTable('severity', false)" class="fa fa-caret-up">
</span>
</a>
</th>
<th><a style="color:black" ng-click="sortColumn('getTimeAgo')">
Timestamp
<span ng-show="sortTable('getTimeAgo')" class="fa fa-caret-down">
</span>
<span ng-show="sortTable('getTimeAgo', false)" class="fa fa-caret-up">
</span>
</a>
</th>
<tbody ng-repeat="t in Ctrl.notifications | filter : search |
filter : Ctrl.customFilter track by $index |
orderBy:sortingFn:sortReverse"
ng-style="$index != 0 ? 'border-top:0px' : ''">
CTRL:
$scope.sortColumn = (sortBy) => {
$scope.sortReverse = !$scope.sortReverse;
$scope.sortBy = sortBy;
};
$scope.sortTable = (sortBy, sortReverse = true) =>
$scope.sortBy === sortBy && $scope.sortReverse === sortReverse;
$scope.sortAlerts = (alert, sortBy) => {
switch (sortBy) {
case 'severity':
return alert.severity;
case 'getTimeAgo':
return alert.getTimeAgo;
default:
return alert[sortBy]
}
};
$scope.sortingFn = (alert) => {
return sortAlerts(alert, $scope.sortBy)
};
答案 0 :(得分:1)
我只是更改了以下内容:
$scope.sortingFn = (alert) => {
return sortAlerts(alert, $scope.sortBy)
};
要
const sortingFn = (alert) => {
return sortAlerts(alert, $scope.sortBy)
};
现在可以使用了。没有错误,没什么...谢谢您的帮助!!
答案 1 :(得分:0)
您必须更改tr的重复次数,因此,对tr的阶次效应
<tr ng-repeat="t in Ctrl.notifications | filter : search |
filter : Ctrl.customFilter track by $index |
orderBy:sortingFn:sortReverse">
<td>{{t.xxx}}</td>
<td>{{t.yyyy}}</td>
</tr>