Reputation: 89
![This is how the DB looks like
]1I have this app that gets an item from the firebase real time DB and displays it nicely but I am not able to edit the item via the app :(
I mean I need somehow to get the unique ID generated when inserting an item ..
For the display part I use Object.entries(data).map((item, index) => (item.key = index));
Upvotes: 0
Views: 63
Reputation: 134
https://firebase.google.com/docs/reference/js/firebase.database.DataSnapshot.html#key
let retrievedItem;
const items = firebase.database().ref(itemsPath);
items.once('value').then(
snapshot => snapshot.forEach(item => {
retrievedItem = {id: item.key, ...item.val()};
})
https://firebase.google.com/docs/reference/js/firebase.database.Reference.html#update
items.child(retreivedItem.id).update(updatedObject);
Upvotes: 1