sis*_*imh 0 angularjs angular-filters ui-select
ui-select我可以在对象的特定字段中过滤搜索吗?或者我应该创建一个自定义过滤器?我看过这个答案,它说它有效,但我的以下代码不起作用:
<ui-select ng-model="model.selected">
<ui-select-match>
<span class="ng-cloak">{{$select.selected.id ? $select.selected.id+ ' (' + $select.selected.sn + ') ' : "Select One" }}</span>
</ui-select-match>
<ui-select-choices repeat="item in items | filter: {id: $select.search.id, sn: $select.search.sn}">
<span ng-bind="(item.id) + ' (' + (item.sn) + ') ' "></span>
</ui-select-choices>
</ui-select>
Run Code Online (Sandbox Code Playgroud)
假设每个iteminitems具有以下属性:
给定以下数据集:
[
{"id":"Ja111", "sn":"Jacobs","fn":"Jim"},
{"id":"Ja222", "sn":"Jagger","fn":"Robert"},
{"id":"Jo111", "sn":"Jones","fn":"Stan"},
{"id":"J111", "sn":"Johnson","fn":"Alfred"},
{"id":"Sm111", "sn":"Smith","fn":"Joe"}
]
Run Code Online (Sandbox Code Playgroud)
使用:
<ui-select-choices repeat="item in items | filter: {id: $select.search, sn: $select.search}">
Run Code Online (Sandbox Code Playgroud)
将在指定字段上执行“与”操作(在本例中为idand sn)(例如,搜索条件“Jo”将仅找到“Stan Jones”)
使用:
<ui-select-choices repeat="item in items | filter: $select.search">
Run Code Online (Sandbox Code Playgroud)
将在所有字段中执行“或”运算(例如,搜索条件“Jo”将找到“Stan Jones”、“Alfred Johnson”和“Joe Smith”)
使用:
<ui-select-choices repeat="item in items | propsFilter: {id: $select.search, sn: $select.search}">
Run Code Online (Sandbox Code Playgroud)
将在指定字段上执行“或”操作(在本例中id为 和sn)(例如,搜索条件“Jo”将找到“Stan Jones”和“Alfred Johnson” - 请注意,它不会找到“Joe Smith”作为过滤器没有看场fn)
以下Plunkr显示了上述示例的实际应用。
根据您的要求(我假设您想要一个“或”过滤器,但仅在特定字段上),我会沿着路线走propsFilter。这似乎也是ui-select Basic Demo使用的。
| 归档时间: |
|
| 查看次数: |
3762 次 |
| 最近记录: |