清除搜索栏后,搜索未显示列表。首先,我要按诊所名称搜索,然后要按保险名称搜索。怎么做? 我在API中有两个功能,但该功能首先是按诊所名称搜索。
我只是尝试简单的搜索。
.html
<ion-searchbar (ionInput)="getClinicName($event)"></ion-searchbar>
<br>
<ion-list *ngIf="listAllClinic">
<button ion-item *ngFor="let data of listAllClinic" (click)=" openClinic(data.clinic_regno,data.clinic_name,data.site,data.clinic_address)" >
{{ data.clinic_name }} <ion-icon name="ios-arrow-forward-outline" item-right></ion-icon>
</button>
.ts
ionViewWillEnter()
{
this.authService.getClinicList()
.then(data => {
this.clinic1 = data;
this.listAllClinic = this.clinic1.clinic_list;
console.log(this.listAllClinic);
});
}
//SEARCH BY CLINIC
getClinicName(ev: any)
{ // Reset items back to all of the items
this.ionViewDidLoad();
// set val to the value of the ev target
var serVal = ev.target.value;
// if the value is an empty string don't filter the items
if (serVal && serVal.trim() != '') {
this.listAllClinic = this.listAllClinic.filter((data) => {
return (data.clinic_name.toLowerCase().indexOf(serVal.toLowerCase()) > -1);
})
}
authservice.ts
getClinicList(){
return new Promise(resolve => {
this.http.get(apiUrl + 'listAllClinic').subscribe(data => {
resolve(data.json());
}, err => {
console.log(err);
});
});
}