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

129
Visualizações
How to fetch items one by one from firebase database?

How can I add only one element to the page that I have added? Now, every time I add a bank, the entire database is pulled out and those banks that have already been added are drawn again.

const sendBankData = () => {
  set(ref(database, "banks/" + bankName.value), {
    bankName: bankName.value,
    interestRate: interestRate.value,
    maximumLoan: maximumLoan.value,
    minimumDownPayment: minimumDownPayment.value,
    loanTerm: loanTerm.value,
  })
    .then(() => {
      successfulPopUp();
    })
    .catch((error) => {
      // errorPopUp();
    });
};

const getBanksFunc = () => {
  const bankRef = ref(database, "banks/");
  onValue(bankRef, (snapshot) => {
    const data = snapshot.val();
    displayBanks(data);
  });
};

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

0

Haven't used Firebase in a long time but if I remember correctly you'd pass the ID of the bank into the ref (const bankRef = ref(database, "banks/ID-OF-THE-BANK");

or you could sort and limit by create date.

about 4 years ago · Juan Pablo Isaza Relatório

0

As commented above mentioned. You need to pass the ID to get the document you just inserted.

So for that you have two options:

One is to set a custom document Id and get the id you just inserted. Or get the doc id with the reference:

const sendBankData = () => {
  set(ref(database, "banks/" + bankName.value), {
    bankName: bankName.value,
    interestRate: interestRate.value,
    maximumLoan: maximumLoan.value,
    minimumDownPayment: minimumDownPayment.value,
    loanTerm: loanTerm.value,
  })
    .then((docRef) => {
      console.log("Document written with ID: ", docRef.id); // Right here you have the if in the of the document you're looking for.

      successfulPopUp();
      // Then you can do the call to get the document:
      const bankRef = ref(database, "banks/${docRef.id}");
           onValue(bankRef, (snapshot) => {
             const data = snapshot.val();
             displayBanks(data);
       });

    })
    .catch((error) => {
      // errorPopUp();
    });
};
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