2 回答
TA贡献1847条经验 获得超11个赞
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | <!doctype html> <html> <head> <meta charset="utf-8"> <title>test</title> <script src="angular.js"></script> <script> var myApp = angular.module("myApp", []); myApp.filter('myfilter',function(){ return function(input,toggle){ var tmp = []; angular.forEach(input,function(value,key){ switch(toggle){ case 'a': if(value>0) tmp.push(value); break; case 'b': if(value>2) tmp.push(value); break; case 'c': if(value<4) tmp.push(value); break; default: tmp = input; } }); return tmp; }; }); myApp.controller("testCtrl", function($scope){ $scope.items = [0,1,2,3,4]; $scope.toggle = ''; }); </script> </head>
<body> <div ng-app="myApp"> <div ng-controller="testCtrl"> <ul> <li ng-repeat="item in items | myfilter:toggle">{{item}}</li> </ul> <input type="checkbox" ng-model="toggle" ng-true-value="'a'" />a <input type="checkbox" ng-model="toggle" ng-true-value="'b'" />b <input type="checkbox" ng-model="toggle" ng-true-value="'c'" />c </div> </div> </body> </html> |
- 2 回答
- 0 关注
- 943 浏览
添加回答
举报