angularJS可以實現常常看到購物車中的升序降序效果

來源:互聯網
上載者:User

標籤:hold   開啟   span   ng-repeat   hal   app   http   控制器   編號   

{"xinxi":[    {"id":100,"name":"baobo","age":12},    {"id":99,"name":"paopo","age":18},    {"id":50,"name":"xinxin","age":55},    {"id":55,"name":"angular","age":20},    {"id":75,"name":"chali","age":15},    {"id":85,"name":"each","age":60},    {"id":98,"name":"hello","age":19},    {"id":68,"name":"zizizi","age":28},    {"id":66,"name":"gegege","age":56},    {"id":77,"name":"fufuf","age":43},    {"id":42,"name":"baobo","age":12},    {"id":54,"name":"menmen","age":32},    {"id":88,"name":"qqqq","age":71},    {"id":69,"name":"laowang","age":22},    {"id":53,"name":"wangwang","age":99},    {"id":1,"name":"dadad","age":88}    ]}

//建立一條json數組

 

 

擷取到數組的內容顯示頁面

 1 <!DOCTYPE html> 2 <html ng-app="atr"> 3     <head> 4         <meta charset="UTF-8"> 5         <title></title> 6         <script src="angular.min.js"></script> 7         <script> 8             var app=angular.module(‘atr‘,[]);//建立模組 9             app.controller(‘test‘,function($scope,$http){//建立控制器test $http取json資料10                 $http.get(‘data.json‘).success(function(data){11                     $scope.arr=data;12                     $scope.selProp="id";13                     $scope.selBy=1;14                 })15             })16         </script>17     </head> 18     <body ng-controller="test">19         <select name="" ng-model="selProp">20             <option value="id">編號排序</option><!--value是尋找數組下標第一個-->21             <option value="name">姓名排序</option>22             <option value="age">年齡排序</option>23         </select>24         <select name="" ng-model="selBy">25             <option value="1">升序</option><!--升序用1表示-->26             <option value="-1">降序</option>27         </select>28         <input type="text" placeholder="搜尋內容" ng-model="value"/>29         <table border="1" cellspacing="0" cellpadding="0">30             <tr>31                 <th>編號</th>32                 <th>姓名</th>33                 <th>年齡</th>34             </tr>                        <!--篩選 filter--> <!--排序數組 三目條件-->35             <tr ng-repeat="value in arr | filter:value | orderBy:selBy == 1 ? selProp:‘-‘ + selProp">36                 <td>{{value.id}}</td>37                 <td>{{value.name}}</td>38                 <td>{{value.age}}</td>39             </tr>40         </table>41     </body>42 </html>

 

 

開啟頁面就可以看到效果了。

angularJS可以實現常常看到購物車中的升序降序效果

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.