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

329
Views
Firebase y Javascript: clasificación de datos mediante consultas de Firestore condicionalmente a través del menú desplegable

Al crear un proyecto se atascó en un punto. Quiero ordenar los datos según el elemento particular seleccionado del menú desplegable. Quiero reemplazar el primer argumento de la función onSnapshot (colRef) con variables de consulta condicionalmente.

El código relevante para el problema: -

datos :

 books(collection) document-1(doc) { "title": "title-1", "rating": 4.0, "year" : xxxx, "createdAt": created time } document-2(doc) { .... .... }

índice.html:

 <div class="sort-dropdown"> <button>Alphabetical Order</button> <button>Rating</button> <button>Date</button> <button>Recent Book</button> </div>

db.js:

 // Initialize services const db = getFirestore() // collection reference const colRef = collection(db, 'books') // query references const q1 = query(colRef, orderBy('title')) const q2 = query(colRef, orderBy('rating')) const q3 = query(colRef, orderBy('date')) const q4 = query(colRef, orderBy('createdAt')) // Getting realtime collection data onSnapshot(colRef, (snapshot) => { snapshot.docChanges().forEach(change => { if(change.type === 'added'){ renderList(change.doc.data(), change.doc.id); } }) }) const renderList = (data, id) => { ... using some dom elements to display data }
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!