Angularjs easy to double-click the sorting function _angularjs

Source: Internet
Author: User

Don't talk much, just look at the sample code

HTML code

 <th class= "col-md-3" ><a href= "ng-click=" desc (' 2 ', La=!la) "> Unit price </a></th>
 <th class=" Col-md-3 "><a href=" "ng-click=" desc (' 3 ', La=!la) "> Sales Amount </a></th>
 <th class=" Col-md-1 " ><a href= "" ng-click= "desc (' 4 ', La=!la)" > Sales quantity </a></th>

Which la=!la is used to determine whether the current click is true orfalse

JS Code

Start by default the Totalnum field is sorted in descending order $scope. Foodsale =ret.sort (function (x,y) {return y.totalnum-x.totalnum;//This means that according to R Et "means receive return array" Inside the Totalnum field in descending order instead return x.totalnum-y.totalnum; is ascending}) $scope. desc= function (Fla,bol) {if (fla== "4") {if (bol==false) {$scope. Foodsale = $scope. Food
     Sale.sort (function (x,y) {return y.totalnum-x.totalnum; }else{Console.log ("BBB") $scope. Foodsale = $scope. Foodsale.sort (function (x,y) {return x.to
     Talnum-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.totalmone
      Y  }}}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 ANGULARJS implementation double-click the entire content of the sorting function, through the above example code can be achieved by double-clicking the order, I hope to learn Angularjs can help.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.