【问题标题】:Ionic 3 - filtering a complex arrayIonic 3 - 过滤复杂数组
【发布时间】:2018-02-01 01:27:44
【问题描述】:

我尝试使用结构过滤来自 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>

搜索系统不适合我

【问题讨论】:

  • 你是如何展示结果的?你也可以显示html 页面吗?
  • 您还有问题吗? console log 说什么?

标签: angular typescript filtering ionic3


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-08-16
    • 1970-01-01
    • 2016-10-22
    • 2011-06-27
    • 1970-01-01
    • 2021-11-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多