离子列表firebase:筛选器不是函数错误

时间:2018-07-28 23:16:50

标签: javascript firebase ionic3 searchfiltercollection

我正在尝试对列表实施搜索过滤器,但出现错误,该怎么办?代码运行正常,但是当我尝试搜索时,出现错误“ 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);
         });
       }

请帮助

0 个答案:

没有答案