javascript – Angular ui-select只过滤一个字段
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了javascript – Angular ui-select只过滤一个字段,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2820字,纯文字阅读大概需要5分钟。
内容图文
![javascript – Angular ui-select只过滤一个字段](/upload/InfoBanner/zyjiaocheng/698/e8949bdd663448baba34dd7fa7b17038.jpg)
情况:
我有一个角度应用程序使用angular ui-select来搜索和选择数据库中的人.
除了一件事,它工作得很好.
用户应该能够使用两个标准在人员之间进行过滤:姓名和电子邮件.
使用普通角度滤波器,我只能过滤其中一个.
如果我尝试过滤这两个字段,它就不再起作用了.
具有一个字段的工作示例:
<ui-select multiple ng-model="database_people.selectedPeople" theme="select2" ng-disabled="disabled" style="width:100%">
<ui-select-match placeholder="Select person...">{{$item.name}} < {{$item.email}} ></ui-select-match>
<ui-select-choices repeat="person2 in list_people | filter: {name: $select.search, db_data_type_id: 5}">
<div ng-bind-html="person2.name | highlight: $select.search"></div>
<small>
email: <span ng-bind-html="''+person2.email | highlight: $select.search"></span>
</small>
</ui-select-choices>
</ui-select>
在过滤器中没有两个字段的工作示例:
<ui-select multiple ng-model="database_people.selectedPeople" theme="select2" ng-disabled="disabled" style="width:100%">
<ui-select-match placeholder="Select person...">{{$item.name}} < {{$item.email}} ></ui-select-match>
<ui-select-choices repeat="person2 in list_people | filter: {name: $select.search, email: $select.search, db_data_type_id: 5}">
<div ng-bind-html="person2.name | highlight: $select.search"></div>
<small>
email: <span ng-bind-html="''+person2.email | highlight: $select.search"></span>
</small>
</ui-select-choices>
</ui-select>
奇怪的是它实际上只适用于第一个角色.
当我键入第一个字符时,它会在两个字段,名称和电子邮件中突出显示它.
但是当我键入第二个字符时,它就不再起作用了
(我在控制台中没有错误).
从ANGULAR SAMPLES开始使用PROPSFILTER的ATTEMP:
<ui-select multiple ng-model="database_people.selectedPeople" theme="select2" ng-disabled="disabled" style="width:100%">
<ui-select-match placeholder="Select person...">{{$item.name}} < {{$item.email}} ></ui-select-match>
<ui-select-choices repeat="person2 in list_people | propsFilter: {name: $select.search, email: $select.search, db_data_type_id: 5}">
<div ng-bind-html="person2.name | highlight: $select.search"></div>
<small>
email: <span ng-bind-html="''+person2.email | highlight: $select.search"></span>
</small>
</ui-select-choices>
</ui-select>
在这种情况下,它完全破坏了,select2中没有数据,我在控制台中出现了一些错误:
Cannot read property 'toString' of null
Cannot read property 'length' of undefined
问题(S):
如何在多个字段之间进行过滤?
我可以使用普通过滤器吗?
或者我必须使用自定义过滤器?
但在这种情况下,为什么不能正常工作?
非常感谢你!
解决方法:
也许是因为相同的值($select.search)用于过滤器电子邮件和名称.
<ui-select-choices repeat="person2 in list_people | filter: {name: $select.search, email: $select.search, db_data_type_id: 5}">
...
这也将解释为什么它只适用于第一个角色.
为每个过滤器使用单独的值来解决此问题:
<ui-select-choices repeat="person2 in list_people | filter: {name: $select.search.name, email: $select.search.email, db_data_type_id: 5}">
...
内容总结
以上是互联网集市为您收集整理的javascript – Angular ui-select只过滤一个字段全部内容,希望文章能够帮你解决javascript – Angular ui-select只过滤一个字段所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。