回首忆惘然
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152<!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>