Without further ado, just look at the sample code
HTML code
<th><a href="" ng-click="desc('2',la=!la)">Unit price</a></th> <th><a href="" ng-click="desc('3',la=!la)">Sales amount</a></th> <th><a href="" ng-click="desc('4',la=!la)">Sales quantity</a></th> where is la=!la used to determine whether the current click is true or false
JS Code
//The default is to the totalnum field in descending order $scope.foodsale =ret.sort(function ( x,y ) { return y.totalnum - x.totalnum;//This means that the totalnum field in ret【represents the receiving and return array】 is arranged in descending order reversely. return x.totalnum - y.totalnum; in ascending order}) $scope.desc= function (fla,bol) { if(fla=="4"){ if(bol==false){ $scope.foodsale =$scope.foodsale.sort(function ( x,y ) { return y.totalnum - x.totalnum; }) }else{ console.log("bbb") $scope.foodsale =$scope.foodsale.sort(function ( x,y ) { return x.totalnum - y.totalnum; }) } }else if(fla=="3"){//totalmoney if(bol==false){ $scope.foodsale =$scope.foodsale.sort(function ( x,y ) { return y.totalmoney - x.totalmoney; }) }else{ $scope.foodsale =$scope.foodsale.sort(function ( x,y ) { return x.totalmoney - y.totalmoney; } ) } }else if(fla=="2"){//price if(bol==false){ $scope.foodsale =$scope.foodsale.sort(function ( x,y ) { return y.price - x.price; }) }else{ $scope.foodsale =$scope.foodsale.sort(function ( x,y ) { return x.price - y.price; } ) } }Summarize
OK, the above is all the content of AngularJS implementing the double-click sorting function. Through the above example code, you can realize double-click sorting. I hope it will be helpful to everyone to learn AngularJS.