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

333
Views
¿Cómo mostrar una plantilla de video si existe un campo de "video" en firestore?

Hola, estoy tratando de mostrar un video usando literales de plantilla, todo funciona bien, pero ahora deseo ocultar la plantilla si el campo de video en Firestore está vacío o no existe.

ingrese la descripción de la imagen aquí

Si el video de campo tiene el valor incrustado en firestore, el video se muestra correctamente

ingrese la descripción de la imagen aquí

Pero si el campo video no tiene ningún valor, la etiqueta iframe seguirá apareciendo y me gustaría ocultarla.

Aquí está mi código

 const video = document.getElementById('video'); let path3 = `Ludolab/offer/list/${idRef}/index/${idCon}/content`; let collRef3 = db.collection(path3); collRef3.onSnapshot((querySnapshot) => { video.innerHTML = ''; querySnapshot.forEach((doc) => { video.innerHTML +=` <iframe class="has-ratio" width="150" height="150" src="https://www.youtube.com/embed/${doc.data().video}" frameborder="0" allowfullscreen> </iframe> ` }); });

Cualquier ayuda se la agradezco con gusto, gracias de antemano.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Puede agregar una declaración if simple que agregue otro iframe solo cuando el campo de video esté presente:

 collRef3.onSnapshot((querySnapshot) => { video.innerHTML = ''; querySnapshot.forEach((doc) => { if (doc.data().video) { // video field present, add iframe video.innerHTML += ` <iframe class="has-ratio" width="150" height="150" src="https://www.youtube.com/embed/${doc.data().video}" frameborder="0" allowfullscreen> </iframe>` } }); });
about 4 years ago · Juan Pablo Isaza Report
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!