angularJS实现二级联动查询以及自定义过滤器的使用

来源:互联网 发布:av狼我们的永久域名 编辑:程序博客网 时间:2024/05/16 09:28
<!DOCTYPE html>
<html lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    
    <script type="text/javascript" src="angular.1.2.10.min.js"></script>
        <title>Title</title>
        <style>
         select{
           width:100px;
           margin-right:20px;
         }
        </style>
</head>
<body ng-app="demo" ng-controller="app">
<select ng-model="search"  ng-options="a for a in na">
</select>
<!--这个位置一定要加上ng-model否则没得值显示-->
<select ng-model="search1" ng-options="name for name in names|filter:search">

<!--去掉默认的空行-->
<option ng-if="false" value=""></option>

</select>
</body>
<script type="text/javascript">
   var app=angular.module("demo",[]);
   app.controller('app',['$scope',function($scope){
       $scope.names=["小王","小明","小张","鹏鹏","大叔","张珊","李四"];
       $scope.na=['小','大','李']
       //console.log($scope.search);
       //设置搜素框的默认值
       $scope.search="小";
       $scope.search1="小明"
   }])
   app.filter('myfilter',function(){
      return function(input,param){
         //console.log(input);
        // console.log(param);
         var newInput=input.filter(function(item,index){
        // console.log(param);
           if(item.indexOf(param)!==-1)
             return item;
         })
         console.log(newInput);
         return newInput;
       }
</script>
</html>