Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

107
Visualizações
I want to display only documents with matching fields in firebase

As in the title, I want to show only documents with matching fields in Firebase.

Now my code using jquery looks like this:

const db = firebase.firestore();

db.collection('product').get().then((product)=>{
    product.forEach((doc)=>{
        var li = "";
        console.log(doc.data())
        if(topic == doc.data().topic){
            li = `
                <div>
                    <img class="${img}" src="${doc.data().img}">
                    <p class="text-500 text-white">${doc.data().title}</p>
                </div>
            `
        }else{
            li = `
                <div>
                    <img class="${img}" src="${doc.data().img}">
                    <p class="text-500 text-white">${doc.data().title}</p>
                </div>
            `
        }
        $(`.app`).append(li)
    })
});
<div class="app"></div>

All documents are now available. For example, if the current URL is "https://example.com?topic=firebase", I want to display only the contents of the documents with the topic field firebase in the documents in a collection called product.

Thank you in advance.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

To get the value of the URL parameter "topic", try this:

function getParameterByName(name, url) {
    if (!url) url = window.location.href;
    name = name.replace(/[\[\]]/g, '\\$&');
    var regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'),
        results = regex.exec(url);
    if (!results) return null;
    if (!results[2]) return '';
    return decodeURIComponent(results[2].replace(/\+/g, ' '));
}

const topic = getParameterByName("topic", window.location.href);
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda