角UI的选择过滤只有一个字段 [英] Angular ui-select filtering only one field

查看:139
本文介绍了角UI的选择过滤只有一个字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

局势:

我在使用角度UI选搜索并选择从人的角度应用一个数据库中。

I have an angular app using angular ui-select to search and select people from a database.

这是工作的罚款,除了一件事。
用户应该能够使用两个标准在人民群众中来筛选:姓名和电子邮件

It is working fine, except one thing. The user should be able to filter among the people using two criteria: name and email.

使用正常的角度过滤器,我能够过滤只是其中之一。
如果我试图筛选这两个领域,它不工作了。



Using the normal angular filter I am able to filter only one of them. If I try to filter both fields, it does not work anymore.

工作有一个字段的例子:

 <ui-select multiple ng-model="database_people.selectedPeople" theme="select2" ng-disabled="disabled" style="width:100%">

    <ui-select-match placeholder="Select person...">{{$item.name}} &lt; {{$item.email}} &gt;</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}} &lt; {{$item.email}} &gt;</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>

但奇怪的是,它确实可以工作,但只有第一个字符。
当我输入第一个字符它强调它在这两个领域,姓名和电子邮件。
但是,当我键入第二个字符它不工作了
(我在控制台没有错误)。

The strange thing is that it actually works BUT only for the first character. When I type the first character it highlights it in both fields, name and email. But when I type the second character it does not work anymore (I got no error in console).


学尝试使用PROPSFI​​LTER FROM ANGULAR样品的:

ATTEMP USING PROPSFILTER FROM ANGULAR SAMPLES:

 <ui-select multiple ng-model="database_people.selectedPeople" theme="select2" ng-disabled="disabled" style="width:100%">

    <ui-select-match placeholder="Select person...">{{$item.name}} &lt; {{$item.email}} &gt;</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>

在此情况下,它完全打破,没有了数据在选择2,我得到在控制台的一些错误:

In this case it broke completely, there is no data anymore in the select2 and I get some errors in the console:

Cannot read property 'toString' of null

Cannot read property 'length' of undefined



的问题(S):

我怎样才能多张领域中筛选?
我可以这样做,使用正常的过滤器?
或者我必须使用自定义过滤器?
但是,在这种情况下,为什么不正常?

How can I filter among mulitple fields? Can I do that using normal filter? Or I have to use a custom filter? But in this case, why is not working properly?

非常感谢你!

推荐答案

也许是因为相同的值($ select.search)用于两个过滤器的电子邮件和名字。

Maybe it's because the same value($select.search) is used for both filters email and name.

<ui-select-choices repeat="person2 in list_people | filter: {name: $select.search, email: $select.search, db_data_type_id: 5}">
...

这也解释了,为什么只有第一个字符的作品。

This will also explains, why it only works with the first character.

使用单独的值,每个过滤器来解决这个问题:

Use separate values for each filter to fix this:

<ui-select-choices repeat="person2 in list_people | filter: {name: $select.search.name, email: $select.search.email, db_data_type_id: 5}">
...

这篇关于角UI的选择过滤只有一个字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆