【发布时间】:2016-10-07 16:57:35
【问题描述】:
我从后端获取一个用于搜索栏的数组
当然它工作正常,但问题是我无法根据搜索栏中的用户类型进行过滤
这是我的搜索栏 html
<ion-toolbar color="primary" >
<ion-searchbar (ionInput)="getItems($event)" (ionCancel)="onCancel($event)" [showCancelButton]="false" ></ion-searchbar>
<ion-list *ngIf="showList">
<ion-item *ngFor="let item of items" (click)="searchBar(item)">
{{ item.name }}
</ion-item>
</ion-list>
</ion-toolbar>
</ion-header>
这是我的 .ts 文件
getItems(ev) {
// Show the results
this.showList = true;
// Reset items back to all of the items
this.initializeItems();
// set val to the value of the searchbar
let val = ev.target.value;
// if the value is an empty string don't filter the items
if (val && val.trim() != '') {
this.items = this.items.filter((item) => {
//return item.toLowerCase().indexOf(val.toLowerCase()) > -1;
return item;
})
} else {
// Hide the results
this.showList = false;
}
}
onCancel(ev) {
// Show the results
this.showList = false;
// Reset the field
ev.target.value = '';
}
【问题讨论】:
-
是用户在用户模型中键入类型字段还是
object的type? -
我有多个对象,您可以在我的 html 内容
item中看到这些对象,我将使用这些对象仅显示名称字段并且它正在工作,但我的问题是如果用户键入像 @ 这样的字母987654326@ 那么对象数组中与c相关的名字应该被过滤掉 -
好的,我正在准备一个plunker。
-
您使用的是哪个版本的 Ionic?
标签: angular autocomplete ionic2 searchbar