关键代码:html
<th class="col-md-3"><a href="" ng-click="desc(‘2‘,la=!la)">单价</a></th> <th class="col-md-3"><a href="" ng-click="desc(‘3‘,la=!la)">销售金额</a></th> <th class="col-md-1"><a href="" ng-click="desc(‘4‘,la=!la)">销售数量</a></th>
其中 la=!la 是用来判断当前点击是true还是false
JS代码
//开始默认为totalnum字段 按照降序排列
$scope.foodsale =ret.sort(function ( x,y ) { return y.totalnum - x.totalnum;//这样表示 按照ret【表示接收返回数组】里面的totalnum字段 按照降序排列 反之 return x.totalnum - y.totalnum; 为升序
})
$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; } ) } }
以上代码 便可实现 双击排序
时间: 2024-10-12 21:37:29