ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

AngularJS filter:search 是如何匹配的 ng-repeat filter:search ,filter:{$:search},只取repeat的item的value 不含labe

2019-05-15 09:50:49  阅读:179  来源: 互联网

标签:search repeat name age filter select


 

 

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

标签:search,repeat,name,age,filter,select
来源: https://www.cnblogs.com/zpzp6/p/10867619.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有