zoukankan      html  css  js  c++  java
  • angular js实现开关效果

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

    实现方法如下

    方法一:定义变量实现点击切换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代码同上。

  • 相关阅读:
    第07组 Alpha冲刺(2/6)
    第07组 Alpha冲刺(1/6)
    第07组 团队Git现场编程实战
    团队项目-需求分析报告
    团队项目-选题报告
    [面试]快来测测你的C++水平
    [技术博客] 数据库1+N查询问题
    【Beta】Scrum meeting 10
    【Beta】Scrum meeting 9
    [技术博客] gitlab快速部署流程
  • 原文地址:https://www.cnblogs.com/lovemomo/p/6690119.html
Copyright © 2011-2022 走看看