码迷,mamicode.com
首页 > 其他好文 > 详细

Angular 学习笔记——ng-repeat&filter

时间:2015-11-23 23:19:24      阅读:221      评论:0      收藏:0      [点我收藏+]

标签:

<!DOCTYPE html>
<html lang="en" ng-app="myApp">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <script type="text/javascript" src="js/angular-1.3.0.js"></script>
    <script>
        var m1 = angular.module(‘myApp‘,[]);
        m1.controller(‘may‘,[‘$scope‘,‘$filter‘,function($scope,$filter){
            var oriArr = [
                { name : "red" , age : "20" },
                { name : "yellow" , age : "40" },
                { name : "blue" , age : "30" },
                { name : "green" , age : "10" }
            ];
            $scope.datelist = oriArr;

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

            $scope.filterfind = function (){
                $scope.datelist = $filter(‘filter‘)(oriArr,$scope.filterVal);
            }

        }])
    </script>
</head>
<body ng-controller=‘may‘>
    <input type="text" ng-model="filterVal"><button ng-click="filterfind()">search</button>
    <table border="1">
        <tr>
            <th ng-click="fnSort(‘name‘)">姓名</th>
            <th ng-click="fnSort(‘age‘)">年龄</th>
        </tr>
        <tr ng-repeat="date in datelist">
            <td>{{date.name}}</td>
            <td>{{date.age}}</td>
        </tr>
    </table>
</body>
</html>

 

Angular 学习笔记——ng-repeat&filter

标签:

原文地址:http://www.cnblogs.com/mayufo/p/4989901.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!