__proto__: Array(0) meaning in javascript- ionic firestore

牧云@^-^@ 提交于 2021-01-29 13:43:02

问题


I am creating an application which has a search bar that connects to firebase and retrieves data and puts it in the search results

I know thanks to a console.log that the database is connecting to the application as can be seen in the array printed here in the console

2) [{…}, {…}]
0: {category: "u11", location: "glasgow"}
1: {category: "u13", location: "stirling"}
length: 2
__proto__: Array(0)

However, my search bar is not returning any results. I am guessing the error is down to the proto object. I have tried doing some research but to no avail. Does anyone know the meaning of this.

I will attach the html and homepage.ts file used to connect and create the search bar. Perhaps there is an error in there. My firestore collection is called competitions and I am trying to filter by location

Homepage.html

<ion-header [translucent]="true">
  <ion-toolbar>
    <ion-title>
      Competition Search
    </ion-title>
  </ion-toolbar>
</ion-header>

<ion-content>
  <ion-searchbar
    showcancelbutton=""
    (ioninput)="filterList($event)"
  ></ion-searchbar>
  <ion-list>
    <ion-item *ngFor="let item of goalList">
      <ion-label>{{ item.competitionlocation }}</ion-label>
    </ion-item>
  </ion-list>
</ion-content>

Homepage.ts

import { Component,OnInit } from '@angular/core';
import { AngularFirestore } from '@angular/fire/firestore';

@Component({
  selector: 'app-home',
  templateUrl: 'home.page.html',
  styleUrls: ['home.page.scss'],
})
export class HomePage {
  public goalList: any[];
  public loadedGoalList: any[];
  constructor(private firestore: AngularFirestore) {}

  ngOnInit() {
    this.firestore.collection(`competition`).valueChanges()
      .subscribe(goalList => {
        this.goalList = goalList;
        this.loadedGoalList = goalList;
        console.log(goalList);
    });
  }

  initializeItems(): void {
    this.goalList = this.loadedGoalList;
  }

  filterList(evt) {
    this.initializeItems();

    const searchTerm = evt.srcElement.value;

    if (!searchTerm) {
      return;
    }

    this.goalList = this.goalList.filter(currentGoal => {
      if (currentGoal.competitionlocation && searchTerm) {
        if (currentGoal.competitionlocation.toLowerCase().indexOf(searchTerm.toLowerCase()) > -1) {
          return true;
        }
        return false;
      }
    });
  }

}

Any help would be appreciated

来源:https://stackoverflow.com/questions/61238472/proto-array0-meaning-in-javascript-ionic-firestore

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!