AngularJS模糊查詢
<!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>
<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>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.