Firebase Push Doesn't Add But Replace (JavaScript)
Solution 1:
When I passed leerling from a regular input type='text' field it worked fine but when I passed it from a select-option input field it failed as described.
Answer :
var leerlingRef = ref.child("leerling").child(_leerling.substring(0,6).trim());
instead of
var leerlingRef = ref.child("leerling").child(_leerling);
on line 15
Solution 2:
I'd suggest using Firebase.update() as it will either create or update a value. Using Firebase.push() removes any, and all data at a certain sub-tree is removed and replaced with what you sent.
So just replace any reference of Firebase.push() with Firebase.update() and your code should work as expected.
Link for ref: Firebase.update()
Note: This will replace any reference of the data that you are updating. So if you have the value "opmID": 1 in Firebase, updating "opmID" to 2 would replace the original "opmID": 1. As Firebase acts like a dictionary, keys can only exist once.
Post a Comment for "Firebase Push Doesn't Add But Replace (JavaScript)"