首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在离子4防火墙中执行搜索/筛选列表

如何在离子4防火墙中执行搜索/筛选列表
EN

Stack Overflow用户
提问于 2020-01-18 06:50:23
回答 2查看 1.1K关注 0票数 0

我试过这么多教程,但我找不到任何解决方案来执行搜索功能。我想通过一个名为booth的领域在StudentList集合中搜索,如果有人愿意帮助我,我会很感激。所以这基本上是我的编码

firebase.service.ts

代码语言:javascript
复制
import { Injectable } from '@angular/core';

import { AngularFirestore, AngularFirestoreDocument,AngularFirestoreCollection, DocumentReference } from '@angular/fire/firestore';

import { AngularFireAuth } from '@angular/fire/auth';

import { Subscription, Observable } from 'rxjs';

import {map, take} from 'rxjs/operators';

import {studl} from '../modal/studl';

@Injectable({

  providedIn: 'root'

})

export class FirebaseService {

  private students: Observable<studl[]>;

  private studCollection: AngularFirestoreCollection<studl>;

  constructor(

     public afs: AngularFirestore,

    public afAuth: AngularFireAuth) {


      this.studCollection = this.afs.collection<studl>('StudentList');

      this.students = this.studCollection.snapshotChanges().pipe(

          map(actions => {

            return actions.map(a => {

              const data = a.payload.doc.data();

              const id = a.payload.doc.id;

              return { id, ...data };

            });

          })

      );

    }

    //getall

    getAllStud(): Observable<studl[]> {

      return this.students;

    }

    //getsingle

    getStudSingle(id: string): Observable<studl> {

      return this.studCollection.doc<studl>(id).valueChanges().pipe(

          take(1),

          map(note => {

            note.id = id;

            return note;

          })

      );

    }

    }
}

Home.html

代码语言:javascript
复制
<ion-content>

  <div class="title-block">

    <div class="heading"></div>

  </div>

  <ion-searchba></ion-searchbar >

  <ion-list>

    <ion-list-header>

      <ion-label>Select your student</ion-label>

    </ion-list-header>

    <ion-item *ngFor="let note of (students | async)">

      <ion-thumbnail slot="start">

        <img src="assets/icon/check.png">

      </ion-thumbnail>

      <ion-label>

        <h5>{{note.name}}</h5>

        <p>Matrix:{{note.matrix}}</p>

        <p>Booth:{{note.booth}}</p>

      </ion-label>



      <ion-button fill="outline" slot="end" [routerLink]="'/role/'+note.id">Evaluate</ion-button>

    </ion-item>

  </ion-list>
</ion-content>

Home.ts

代码语言:javascript
复制
import { Component, OnInit } from '@angular/core';

import { AuthenticateService } from '../services/authentication.service';

import { LoadingController } from '@ionic/angular';

import { Router, ActivatedRoute, Params } from '@angular/router';

import { NavController, ModalController } from '@ionic/angular';

import { FirebaseService } from '../services/firebase.service'

import { AngularFirestore } from '@angular/fire/firestore';

import { FormControl } from '@angular/forms';

//import { debounceTime } from 'rxjs/operators';

import { studl } from '../modal/studl';

import { Observable } from 'rxjs';

@Component({

  selector: 'app-studlist',

  templateUrl: './studlist.page.html',

  styleUrls: ['./studlist.page.scss'],

})

export class StudlistPage implements OnInit {

  public students: Observable<studl[]>;

  constructor(

    public loadingCtrl: LoadingController,

    private authService: AuthenticateService,

    private fService: FirebaseService,

    private firestore: AngularFirestore,

    private router: Router,

    private route: ActivatedRoute,

    private navCtrl: NavController

  ) { }

  ngOnInit() {

    this.students = this.fService.getAllStud();

  }

Studl.modal.ts

代码语言:javascript
复制
export interface studl {

    id?: any;

    name: string;

    booth: string;

    matrix: string;

    cspmark:string;

    exmark:string;

    svmark:string;

}

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2020-01-18 08:18:46

Filter data from Firestore whit angularfire

有一个类似的问题,你需要的是一个答案在链接above.If中没有很好地为你服务,然后重新评论答案来解决它。

票数 0
EN

Stack Overflow用户

发布于 2020-01-22 20:18:49

您可以使用角阵列运算符进行搜索。只要你拥有的对象是一个数组。

例如

代码语言:javascript
复制
this.students = this.students.filter((student) => student.booth.toLowerCase() === 'search Terms');

或者,如果你想使用和观察,你可以使用管道和地图。

代码语言:javascript
复制
  ngOnInit() {

    this.students = this.fService.getAllStud();
    this.students.pipe
    (
     map(
         students => {
          return students.filter((student) => 
          student.booth.toLowerCase() === 'search Terms');
         }
        )
    )

  }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59798232

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档