我正在尝试对列表实施搜索过滤器,但出现错误,该怎么办?代码运行正常,但是当我尝试搜索时,出现错误“ TypeError:this.items.filter不是函数”
下面的我的代码
export class ShoppingListPage {
shoppingListRef$: FirebaseListObservable<ShoppingItem[]>;
initialItems:any;
public items:any;
constructor(public navCtrl: NavController, public navParams: NavParams,
private db: AngularFireDatabase) {
this.shoppingListRef$ = this.db.list('shopping-list');
this.items = this.shoppingListRef$;
}
initializeItems() {
this.items = this.items;
}
getItems(ev) {
// Reset items back to all of the items
this.initializeItems();
// set val to the value of the ev target
var 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: any) => {
return (item.itemName.toLowerCase().indexOf(val.toLowerCase()) > -1);
});
}
请帮助