AngularJS模糊查询

来源:互联网 发布:microsoft fix it win8 编辑:程序博客网 时间:2024/06/06 08:29
<!DOCTYPE html>
<html>


<head>
<meta charset="UTF-8">
<title></title>
<script type="text/javascript" src="js/angular.min.js"></script>


</head>


<body ng-app="myApp" ng-controller="myCtrl">
查询:<input type="text" ng-model="cx" />
<p>{{datas|mohu:cx}}</p>


<script type="text/javascript">
//创建模块
var mo = angular.module("myApp", []);
mo.controller("myCtrl", function($scope) {


//创建数组
$scope.datas = ["lisi", "zhangsan", "wangwu", "zhaoliu", "laoqi"];
})


//创建自定义过滤
mo.filter("mohu", function() {


return function(input, d) {
//创建新的数组
var newData = [];
//遍历
for(var i = 0; i < input.length; i++) {

                         var da =input[i];
                         
if(da.indexOf(d) != -1) {
newData.push(da);
}
}
return newData;


}
})
</script>
</body>


</html>