angular - Ionic 3 - 过滤复杂数组

标签 angular typescript filtering ionic3

我尝试过滤来自具有结构的 json 的数组

{ID: "2031", title: "title 1", image: "http://wwwsite.com/im.jpg", url: 
       "url...", Goal: "3000000", …}

我的数组名称是“loadedprojects”,这是过滤函数:

getItems(ev: any) {
    // Reset items back to all of the items
      this.getloadedproject();

    // 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.loadedprojects = this.loadedprojects.filter((project) => {
        console.log( this.loadedprojects);
        return (project.title.indexOf(val) > -1);
      })
    }
  }

在 html 页面上:

<ion-searchbar  (ionInput)="getItems($event)"></ion-searchbar>

预览页面html:

<ion-card *ngFor="let project of loadedprojects">
      <img  src="{{project.image}}" />
      <ion-card-content>
        <ion-card-title>{{ project.title }}</ion-card-title>
        <p>{{ project.country }}</p>
      </ion-card-content>

      <ion-grid >
        <ion-row>
          <ion-col col-6> {{ 'Goal' | translate }}</ion-col>
          <ion-col col-6 class="value-amount"> {{ project.Goal | number }} رق </ion-col>
        </ion-row>

        <ion-row>
          <ion-col col-6> {{ 'Donations' | translate }}</ion-col>
          <ion-col col-6 class="value-amount"> {{ project.Donation | number }} رق </ion-col>
        </ion-row>
        <ion-row>
          <ion-col col-6> {{ 'Donnors' | translate }}</ion-col>
          <ion-col col-6 class="value-amount"> {{ project.nbr_donnors }} </ion-col>
        </ion-row>
        <ion-row>
          <ion-col col-12>
            <button ion-button block class="donate_button" (click)="donation_options(project.ID, project.title, project.image)">{{ 'Donate' | translate }}</button>
          </ion-col>
        </ion-row>
      </ion-grid>



    </ion-card>

搜索系统不适合我

最佳答案

你不需要使用[(ngModel)]="keyword"。你可以尝试如下所示。

<ion-searchbar (ionInput)="getItems($event)"></ion-searchbar>

关于angular - Ionic 3 - 过滤复杂数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45840011/

相关文章:

php - MySQL/PHP - 过滤非数字字段的数值

json - Angular 6 - 解析 JSON

reactjs - React 项目中的 typescript 不再识别 'as' 关键字

按涉及 Qlik Sense 中多个字段的计算度量进行过滤

javascript - 如何对 Map 类型的对象进行字符串化

Angular:扩展服务和传递参数

c++ - OpenCV : homomorphic filter

angular - 这种在 Angular 中创建 HTTP 服务的方法是否正确?

angular - 如何使用 Electron 和 Angular 与NamedPipe连接

angular - 语法错误 : Unexpected token < in JSON at position 0 at