【问题标题】:Searchbar in Ionic is not workingIonic 中的搜索栏不起作用
【发布时间】:2018-07-22 19:46:43
【问题描述】:

我正在尝试在 Ionic 中进行搜索,但它在底部显示错误。 首先,我从 API 中检索一些数据,我想过滤这些结果。

以下是我的html,它显示了数据的检索和一个搜索栏

<ion-header>

 <ion-navbar color="toolcolor">
<ion-title>Doctor Appointments</ion-title>
<!--<ion-buttons color="toolcolor" end><button id="search" 
(click)="search()"><ion-icon name="search" color="light"></ion-icon></button> 
</ion-buttons> -->
 <ion-searchbar [(ngModel)]="ev" (ionInput)="getItems($ev)"></ion-searchbar>
 </ion-navbar>

 </ion-header>


    <ion-content padding> 

     <div class="card">
     <ion-item color="toolcolor">

     <ion-label color="light">Select Date</ion-label>
     <ion-datetime   displayFormat="MMM DD YYYY" [(ngModel)]="event.month" > 
    </ion-datetime>
    </ion-item>
    <br>
    <div *ngFor="let item of items">
    <button class="doc_appoint" (click)="patientdetails()">
     <ion-label id="pat_det">Time:{{ item.time }}</ion-label>
     <ion-label id="pat_det">Patient Name:</ion-label>
     <ion-label id="pat_det">Patient ID:{{ item.PatientId }}</ion-label>
    </button>
    <br><br><br><br><br><br>
    </div>
   </div>



   </ion-content>

我的ts,它显示了搜索栏功能 不知道哪里错了

 getItems(ev) {
   this.show();
   var val = ev.target.value;
    if (val && val.trim() != '') {
    this.items = (this.items).filter((item) => {

    return ((item.PatientId).toLowerCase().indexOf(val.toLowerCase()) > -1);
    })
    }
    }

还有我的错误

我不知道如何克服这一点。 欢迎任何建议。 提前致谢。

【问题讨论】:

  • 在您的 getItems 方法中 ev 似乎未定义。确保您没有在代码中的某处覆盖它。也许还可以尝试删除[(ngModel)]="ev" 以防止变量冲突...

标签: typescript ionic3 searchbar


【解决方案1】:

你不需要[(ngModel)]="ev",删除它。

在函数getItems 中将签名从getItems(ev) 更改为getItems(ev: any)

【讨论】:

    猜你喜欢
    • 2022-06-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-18
    • 2018-06-05
    • 2018-03-12
    相关资源
    最近更新 更多