我正在实施一个离子2项目,同时对来自API的数据进行过滤搜索。数据正确向右拉,但我的问题是将其过滤掉
import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams, LoadingController, AlertController } from 'ionic-angular';
import { Http } from '@angular/http';
import 'rxjs/add/operator/map';
import { TransactionsPage} from '../../pages/pages'
/**
* Generated class for the RoutesPage page.
*
* See https://ionicframework.com/docs/components/#navigation for more info on
* Ionic pages and navigation.
*/
@IonicPage()
@Component({
selector: 'page-routes',
templateUrl: 'routes.html',
})
export class RoutesPage {
items: any;
constructor(public navCtrl: NavController,
public navParams: NavParams,
public http: Http,
public LoadingController: LoadingController,
public alertCtrl: AlertController,
) {
}
ionViewDidLoad() {
let loader = this.LoadingController.create({
content: 'Please Wait'
});
loader.present().then(()=>{
this.http.get('assets/locations.json').map(res => res.json()).subscribe(data =>{
console.log(JSON.stringify(data));
this.items= data;
});
loader.dismiss();
})
}
getItems(ev: any) {
// Reset items back to all of the items
this.ionViewDidLoad();
// 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.items = this.items.filter((item) => {
return (item.toLowerCase().indexOf(val.toLowerCase()) > -1);
})
}
}
}
当我开始在文本框中输入时,我在浏览器控制台中收到错误,并显示
item.toLowerCase is not a function
有关如何完成此操作的任何帮助?感谢