angularJS可以实现常常看到购物车中的升序降序效果

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了angularJS可以实现常常看到购物车中的升序降序效果相关的知识,希望对你有一定的参考价值。

{
"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可以实现常常看到购物车中的升序降序效果的主要内容,如果未能解决你的问题,请参考以下文章

Mysql——实现按字段部分升序,部分降序的方法

java中,如何实现集合的升序和降序排列

javascript实现表格升序降序排列

轻松Angularjs实现表格按指定列排序

unity3dC#的List升序降序排序

java Collections.sort实现的排序是升序还是降序