首页 > Web开发 > 详细

angular js实现开关效果

时间:2017-04-10 18:32:15      阅读:176      评论:0      收藏:0      [点我收藏+]

功能:实现点击排序,再点击排倒序。

实现方法如下

方法一:定义变量实现点击切换true或false,代码为:

         $scope.lidata = [
                {"name":"Terry","age":12},
                {"name":"Jenifer","age":45},
                {"name":"Garry","age":36},
                {"name":"Tao","age":24},
                {"name":"Lee","age":34},
         ];
     $scope.sortTmp = false;    $scope.sortFn = function(arg){   $scope.sortTmp = !$scope.sortTmp; //在这实现点击的切换   $scope.lidata = $filter(‘orderBy‘)($scope.lidata, arg, $scope.sortTmp); }

其中对应的html代码为:

        <table style="margin-left:20px">
            <tr>
                <th ng-click = "sortFn(‘name‘)">姓名</th>
                <th ng-click = "sortFn(‘age‘)">年龄</th>
            </tr>
            <tr ng-repeat = "data in lidata">
                <td>{{data.name}}</td>
                <td>{{data.age}}</td>
            </tr>
        </table>

方法二:函数也是对象,可以赋属性。

        $scope.sortFn = function(arg){
            arguments.callee["sortFn" + arg] = !arguments.callee["sortFn" + arg]
            $scope.lidata = $filter(‘orderBy‘)($scope.lidata,arg,arguments.callee["sortFn" + arg]);
        }    

html代码同上。

angular js实现开关效果

原文:http://www.cnblogs.com/lovemomo/p/6690119.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!