离子v3搜索栏对象过滤器

时间:2019-06-19 20:16:05

标签: ionic-framework ionic3

我想使用各种条件过滤对象的结果

我对IONIC还是很陌生,并希望完成过滤结果的任务

alt text

constructor(public navCtrl: NavController, public navParams: NavParams, private searchServ : SearchService,) {
        this.allCreativeUsers();
    }

    allCreativeUsers() {

        this.searchServ.getAllCreatives().then(
            resp => {
                console.log( typeof (resp));
                console.log(resp);
                this.allPeople = resp;
            }
        );

    }

    filterItems(ev: any) {
        let val = ev.target.value;

        if (val && val.trim() !== '') {
            // Get The users from the Object Result and 
        }
    }

当我开始输入某人的姓名时,我希望能够过滤对象并在列表中显示该人的姓名。

Like the do in the examples

1 个答案:

答案 0 :(得分:0)

这将过滤

 filterdata:any

 constructor(public navCtrl: NavController, public navParams: NavParams, private 
       searchServ : SearchService,) {
          this.allCreativeUsers();
         }

 allCreativeUsers() {

    this.searchServ.getAllCreatives().then(
        resp => {
            console.log( typeof (resp));
            console.log(resp);
            this.allPeople =  this.filterdata = resp;
        }
    );

 }

 filterItems(ev: any) {
    let val = ev.target.value;

    if (val && val.trim() !== '') {
        // Get The users from the Object Result and 

    this.allPeople =  this.filterdata.filter(r =>
       (<string>r.route).includes(val));

    }
  }