Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

244
Vistas
I would like to input data based on categories in Firebase realtime database

I would like to get the output in image 1, such that whenever I select book as itemcategory and type my code or barcode all data such as itemname and itemprice etc go under book category and new code/barcode.

image1

What I currently have is in image2. If I input data again under book it just replaces the data already there, it doesn't add a new record based on category and (code/itembarcode)- both these are same.

image2

function insertData(){
  set(ref(db, "ItemByCategory/" +category.value),{
    Code: barcode.value,
    Category: category.value,
    ItemName: itemname.value,
    ItemPrice: itemprice.value,
  })
  .then(() =>{
    alert("data stored successfully");
  })
  .catch((error)=>{
    alert("unsuccessful, error"+error);
  });
}

This is my insert code.

How do I go about this?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

It sounds like your want:

set(ref(db, "ItemByCategory/" +category.value+"/"+barcode.value),{
  Code: barcode.value,
  Category: category.value,
  ItemName: itemname.value,
  ItemPrice: itemprice.value,
})

Or, with a ES6 template literal:

set(ref(db, `ItemByCategory/${category.value}/${barcode.value}`,{
  ...
})
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda