zoukankan      html  css  js  c++  java
  • AngularJS filter:search 是如何匹配的 ng-repeat filter:search ,filter:{$:search},只取repeat的item的value 不含label

     

     

    1.  filter可以接收参数,参数用 : 进行分割,如下:

    {{ expression | filter:argument1:argument2:... }}

    2.   filter参数是 对象 ,匹配属性中含有value的

    复制代码
    $scope.childrenArray = [
            {name:'kimi',age:3},
            {name:'cindy',age:4},
            {name:'anglar',age:4},
            {name:'shitou',age:6},
            {name:'tiantian',age:5}
        ];
    
    {{ childrenArray | filter : {name : 'i'} }} //参数是对象,匹配name属性中含有i的
    复制代码

    示例:angular filter多个字段搜索

    复制代码
    <input type="text" ng-model="search ">
    
    <!--<li ng-repeat="user in data.users | filter:{name:search}>  --> 
    <!--此时只搜索了name字段-->
    
    <!--搜索name字段、account字段-->
    <li ng-repeat="user in data.users | filter:{name:search}:{account:search}> 
    <span ng-bind="user.name"></span>
    <span ng-bind="user.account"></span>
    </li>
    复制代码

    3.  没有指定过滤哪个字段的情况下,默认filter会匹配所有字段(name、account)的值,类似 多个字段搜索

    ng-repeat="user in data.users | filter:search

    4. $ 匹配 对象 所有属性 和  嵌套对象属性

    <li ng-repeat="user in data.users | filter:{$:search}> 

    5.  bind ng-model to the “value” of selected item  instead of item for ui-select

    复制代码
      <ui-select ng-model="fm.countryCode" id="countryCode">
          <ui-select-match placeholder="Select a country...">{{$select.selected.label}}</ui-select-match>
          <ui-select-choices repeat="item in countries | filter: $select.search" value="{{$select.selected.value}}">
              <div ng-bind-html="item.label | highlight: $select.search"></div>
              <small ng-bind-html="item.value | highlight: $select.search"></small>
          </ui-select-choices>
      </ui-select>   
    复制代码

    Currently it's just setting fm.countryCode to the whole country item.

    For example if I select Afghanistan, fm.countryCode will be set to {"value":"AF","label":"Afghanistan"}.

    What I want is "AF".

    so change  the repeat part

    <ui-select-choices repeat="item in countries | filter: $select.search" value="{{$select.selected.value}}">

    to

    <ui-select-choices repeat="item.value as item in countries | filter: $select.search" value="{{$select.selected.value}}">

     示例:

    复制代码
                                                <ui-select ng-model="networkDefaultValue.resourceId" name="networkname" theme="bootstrap" ng-change="setInputDefaultValue(['resource_id'],networkDefaultValue.resourceId,networkDefaultValue.isResourceIdInput)">
                                                    <ui-select-match allow-clear="true" placeholder="{{'Select an option'|translate}}">{{$select.selected.name + ' - ' + $select.selected.properties.datacentername}}</ui-select-match>
                                                    <ui-select-choices repeat="resource.id as resource in totalNetworks | filter: { $ : $select.search}">
                                                        <div ng-bind-html="resource.name + ' - ' + resource.properties.datacentername | highlight: $select.search"></div>
                                                    </ui-select-choices>
                                                </ui-select>
    复制代码

    参考网址:

    走进AngularJs(七) 过滤器(filter)


    AngularJS filter:search 是如何匹配的 ng-repeat filter:search

  • 相关阅读:
    0级搭建类006-Oracle Solaris 安装 (10.13) 公开
    0级搭建类005-Oracle Solaris Unix安装 (11.4) 公开
    0级搭建类004-中标麒麟 Linux 安装 (V7.0) 公开
    0级搭建类003-CentOS Linux安装 (CentOS 7)公开
    0级搭建类002-Oracle Linux 8.x安装(OEL 8.0) 公开
    0级搭建类001-RedHat Enterprise Linux 8 安装(RHEL 8) 公开
    1级搭建类105-Oracle 19c 单实例 FS(19.3+RHEL 8)公开
    1级搭建类103-Oracle 12c 单实例 FS(12.2.0.1+RHEL 7)公开
    1级搭建类102-Oracle 11g 单实例 FS(11.2.0.4+RHEL 7)公开
    1级搭建类101-Oracle 11g 单实例 FS LVM(11.2.0.4+RHEL 5)公开
  • 原文地址:https://www.cnblogs.com/zpzp6/p/10867619.html
Copyright © 2011-2022 走看看