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

240
Views
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 answers
Answer question

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 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!