An_form 정렬

3222 단어


    
        
        
        <script type="text/javascript" src="js/angular.js"/>
          <style>  
            .redColor{  color:red;  }  
          </style>  
        <script>
            var app=angular.module("myApp",[]);
            app.controller("myCtrl",function($scope){
                $scope.goods=[{"id":80,"name":"iphone","price":5400},
                {"id":1200,"name":"ipad mini","price":2200},
                {"id":500,"name":"ipad air","price":2340},
                {"id":29,"name":"ipad","price":1420},
                {"id":910,"name":"imac","price":15400}];
                $scope.orderColumn="name";
                $scope.orderSign="-";
                $scope.sortProduct=function(sortColumn){
                    $scope.orderColumn=sortColumn;
                    if($scope.orderSign=="-"){
                        $scope.orderSign="";
                    }else{
                        $scope.orderSign="-";
                    }
                }
                 $scope.remove = function(name) {
                    if(confirm(" "+name+" ")) {
                        var p;
                        for(index in $scope.goods ){
                            p=$scope.goods[index];
                            if(p.name==name){
                                $scope.goods.splice(index,1);
                            }
                        }
                    }
                }
                 $scope.removeAll = function() {
                    if(confirm(" ?")) {
                        $scope.goods = [];
                    }
                }

            });
        </script>
    
    
        <input type="text" ng-model="search" placeholder=" "/>
        <button ng-click="removeAll()"> </button>
        <table border="1" cellspacing="0">
            <tr>
                <td> <button ng-click="sortProduct('id')">^</button></td>
                <td> <button ng-click="sortProduct('name')">^</button></td>
                <td> <button ng-click="sortProduct('price')">^</button></td>
                <td><a> </a></td>
            </tr>
            <tr ng-repeat="x in goods | filter:{'name':search}|orderBy:(orderSign + orderColumn)">
                <td>{{x.id }}</td>
                <td>{{x.name}}</td>
                <td>{{x.price |currency :"(RMB)"}}</td>
                <td ng-click="remove(x.name)"><a> </a></td>
            </tr>
        </table>
    


</code></pre> 
</article>
                            </div>
                        </div>

좋은 웹페이지 즐겨찾기