Как получить данные из коллекций пожарных хранилищ путем фильтрации данных - PullRequest
0 голосов
/ 23 апреля 2019

Я участвую в проекте angular с google cloud firestore. Я хочу получить данные из firebase, рассмотрев атрибут вложенной коллекции. Вы можете увидеть в моей базе данных.

enter image description here

Я могу получить данные без фильтрации следующим образом

service.ts

import { Injectable } from '@angular/core';
import { AngularFirestore } from '@angular/fire/firestore';
import { Processing } from './processing.model';
import { from } from 'rxjs';

@Injectable({
providedIn: 'root'
})
export class ProcessingService {
    patients: Processing;

    constructor(private firestore: AngularFirestore) {}

    /**
    * I'm using this function for retrieve data.
    * It is working
    * I want to filter data using attribute
    */

    getPatients() {
        return this.firestore
        .collection('patients')
        .doc('patientData')
        .snapshotChanges();
    }

}

component.ts

import { Component, OnInit } from '@angular/core';
import { Processing } from './processing.model';
import { ProcessingService } from './processing.service';

@Component({
selector: 'ngx-processing',
styles: [],
template: `
    <ng2-smart-table
    [settings]="settings"
    (createConfirm)="addData($event)"
    (editConfirm)="editData($event)"
    (deleteConfirm)="deleteData($event)"
    [source]="list"
    ></ng2-smart-table>
`
})
export class ProcessingComponent implements OnInit {
    list: Processing[] = [];
    constructor(private service: ProcessingService) {}

    ngOnInit() {
        this.service.getPatients().subscribe(actionArray => {
        let a = actionArray.payload.get('data');
        if (a) {
            this.list = a;
        }
        });
    }

    //I removed the displaying part of the list for your convenient. but it is work. 
    //There is no any error in displaying.

}

Я покажу вам кратко выше функции.

Я использовал эти функции для извлечения всех данных из таблицы.

Funciton 01

getPatients() {
    return this.firestore
    .collection('patients')
    .doc('patientData')
    .snapshotChanges();
}

Funciton 02

 ngOnInit() {
    this.service.getPatients().subscribe(actionArray => {
       let a = actionArray.payload.get('data');

       if (a) {
          this.list = a;
       }

    });
}

Я хочу отфильтровать эти данные по атрибуту с именем level. Тогда я хочу взять данные, которые level= 'p'. так как я изменяю эту функцию.

...