Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

217
Views
Filtrado con múltiples campos en la base de datos en tiempo real de firebase y angularfire

Debido a la limitación de la base de datos en tiempo real de Firebase para filtrar en múltiples campos, estoy tratando de filtrar los datos en el lado del cliente. He declarado una variable que coincide con un campo en el conjunto de resultados. Pero no puedo actualizar los resultados mientras cambio el campo. Sé que hay algo mal con la forma en que estoy filtrando los datos. ¿Podría alguien, por favor, mostrar algunos caminos para lograr esto?

Mecanografiado:

 import { Component, OnInit } from '@angular/core'; import { AngularFireDatabase } from '@angular/fire/compat/database'; import { Observable } from 'rxjs'; import { map } from 'rxjs/operators'; import { Item } from '../models/item'; @Component({ selector: 'test-component', templateUrl: './test-component.html', styleUrls: ['./test-component.scss'] }) export TestComponent implements OnInit { itemRef: Observable <Item[]> = new Observable(); group_id: number = 5; //dynamic currentTypeSelected: number = 2; //dynamic currentTypeBehaviorSubject: BehaviorSubject<number> = new BehaviorSubject<number>(2); constructor( private _db: AngularFireDatabase, ){ } ngOnInit(): void { this.itemRef = this._db.list('/items', ref => ref.orderByChild('group_id').equalTo(this.group_id)).snapshotChanges().pipe( map(action => action.map(a => { const obj = a.payload.val(); return new Item(obj); }).filter(item => item.type == this.currentTypeSelected)) ) } }

Modelo:

 <div *ngFor="let item of itemRef | async"> <pre>{{ item | json}}</pre> </div>

Actualización: Pude resolver este problema con el siguiente código. No estoy seguro si este es el método adecuado para resolver esto.

 this.itemRef = combineLatest([this._db.list('/items', ref => ref.orderByChild('group_id').equalTo(this.group_id)).snapshotChanges(), this.itemType.asObservable()]).pipe( map(results => results[1].map(a => { const obj = a.payload.val(); return new Item(obj); }).filter(item=>item.type==results[0]) ) );
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!