zoukankan      html  css  js  c++  java
  • AngularJS自定义过滤器

    <!DOCTYPE html>
    <html lang="en">
    <head>
    	<meta charset="UTF-8">
    	<title>自定义过滤器</title>
    	<script src="angular-1.5.8.min.js"></script>
    	<style>
    		* {
    			margin: 0;
    			padding: 0;
    			list-style: none;
    		}
    		ul {
    			 800px;
    			margin: 100px auto 0;
    		}
    		.odd {
    			color: red;
    		}
    		.even {
    			color: blue;
    		}
    	</style>
    </head>
    <body ng-app="myApp">
    	<div ng-controller="myCtrl"ng-init="score=95">
    		<ul>
    			<li>请输入性别:<input type="text" ng-model="input"></li>
    			<li>请输入年龄:<input type="text" ng-model="input1"></li>
    			<li>请输入姓名:<input type="text" ng-model="input2"></li>
    			<li ng-repeat="item in data | filter: input | filter: {age: input1} | filter: {name: input2}" ng-class-odd="'odd'" ng-class-even="'even'">
    				<span>name: {{item.name}}</span>
    				<span>sex: {{item.sex}}</span>
    				<span>age: {{item.age}}</span>
    			</li>
    		</ul>
    	</div>
    
    	<script>
    		var app = angular.module("myApp",[]);
    		app.controller("myCtrl", ["$scope", function (scope) {
    			scope.data = [
    				{'name':'Han','sex':'男','age': 22},
    				{'name':'Zhang','sex':'女','age': 23},
    				{'name':'Han','sex':'男','age': 0},
    				{'name':'Han','sex':'男','age': 22},
    				{'name':'Zhang','sex':'女','age': 23},
    				{'name':'Han','sex':'男','age': 0}
    			]
    		}]);
    		app.filter('myfilter', function () {
    			return function (input) {
    				var arr = [];
    				for (var i = 0; i < input.length; i++) {
    					if (input.sex == "男") {
    						arr.push(input[i]);
    					}
    				}
    				return arr;
    			}
    		});
    	</script>
    </body>
    </html>
    

      

  • 相关阅读:
    UML中的构件图
    Extjs4 中的gird
    【转载】C#实现线程安全的网络流
    [转载]组播
    【转载】wcf综合运用之:大文件异步断点续传
    【转载】WCF热门问题编程示例(4):WCF客户端如何异步调用WCF服务?
    【转载】特殊用途的IP地址介绍
    [转载]C# HashTable
    c宏定义实战
    c异或加密与解密
  • 原文地址:https://www.cnblogs.com/handsomehan/p/6148568.html
Copyright © 2011-2022 走看看