我有订单的表,我想在第二次点击时点击和反向排序它们。在第一次点击排序工作正常,但在第二次点击反向排序不起作用。它抛出解析异常。这是我的代码 HTML
<tr>
<th><a href="#" ng-click="changeOrder('merchant.id');" ng-dblclick="forDoubleClick('merchant.id')"><abbr title="Merchant ID">M.I.</abbr></a></th>
</tr>
<tr dir-paginate="item in serverData | orderBy : orderBy | filter:filterData | itemsPerPage: itemPerPageValue"></tr>
...
我的JS代码
$scope.orderBy = 'value';
$scope.changeOrder = function(value) {
$scope.orderBy = value;
}
$scope.forDoubleClick = function(value)
{
$scope.orderBy = value + " : reverse ";
}
答案 0 :(得分:0)
您不需要$scope.forDoubleClick
功能,我只添加了一个变量$scope.currentOrder = 1;
,它将决定Sort
顺序。即%
或remainder
等于0
按Ascending
按Descending
订单排序。
并在每个$scope.currentOrder
click
$scope.currentOrder = 1;
$scope.changeOrder = function(value) {
$scope.currentOrder++;
if($scope.currentOrder % 2 != 0)
$scope.orderBy = '-' + value;
}else{
$scope.orderBy = value;
}
答案 1 :(得分:0)
你能尝试这样的事吗?
$scope.sortOrder = 'ASC';
$scope.changeOrder = function(value) {
if($scope.sortOrder === 'ASC') {
$scope.orderBy = value;
$scope.sortOrder = 'DSC';
} else {
$scope.orderBy = value + " : reverse ";
$scope.sortOrder = 'ASC';
}
}
答案 2 :(得分:0)
而不是ng-click="changeOrder('merchant.id');"
put
ng-click="changeOrder(merchant.id);"
同样适用于ng-dblclick
。