第二次点击时的逆序

时间:2017-04-10 08:31:24

标签: javascript html angularjs

我有订单的表,我想在第二次点击时点击和反向排序它们。在第一次点击排序工作正常,但在第二次点击反向排序不起作用。它抛出解析异常。这是我的代码 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 ";
    }

3 个答案:

答案 0 :(得分:0)

您不需要$scope.forDoubleClick功能,我只添加了一个变量$scope.currentOrder = 1;,它将决定Sort顺序。即%remainder等于0AscendingDescending订单排序。

并在每个$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