I have an object like:
var _json = { "objects":[{
"type":"path", "originX":"center", "originY":"center", "left":48.59,
"top":132.5, "width":64.5,"height":173, "fill":null,"stroke":"#3f7cc4",
"strokeWidth":12,"strokeDashArray":null
}]}
I save this object using Firebase as:
var myDataRef = new Firebase(<...>);
myDataRef.child("saved_projects").child(authData.uid).update({'P3': _json});
But, when I retrieve the same using Firebase on
method and get the value as:
snapshot.val()
I get the object but keys with null
values got removed i.e. I only got:
{"objects":[ {"type":"path", "originX":"center",
"originY":"center","left":48.59, "top":132.5,"width":64.5,
"height":173, "stroke":"#3f7cc4","strokeWidth":12
}]}
This is causing me some weird issues since I'm using Fabric.js
and it needs these values.
Please help!
EDIT / UPDATE(Hack)
For the time being, I'm using a weird HACK, before storing the object to Firebase I'm converting all the null
values to 0
. But I want to know a nicer way to do.
function recursivelyReplaceNullToZero(j) {
for (var i in j){
if (typeof j[i] === "object") {
recursivelyReplaceNullToZero(j[i]);
}
if (j[i] === null) {
j[i] = 0;
}
}
}
recursivelyReplaceNullToZero(_json);
A null value, on the other hand, indicates that the current user is not signed in using any of the Firebase authentication providers. As declared, these rules dictate that only authenticated app users are allowed read and write access to the project's realtime database data.
Nothing is getting stored, because you are not storing anything, you need to use setValue() to store data. The child() gets reference to a location in the database.
Firebase is categorized as a NoSQL database program, which stores data in JSON-like documents. In Firebase, a document is a set of key-value pairs defined by a schema.
For the time being I'm using a weird HACK, before storing the object to Firebase I'm converting all the null values to 0. But I want to know much nicer way, please!
function recursivelyReplaceNullToZero(j) {
for (var i in j){
if (typeof j[i] === "object") {
recursivelyReplaceNullToZero(j[i]);
}
if (j[i] === null) {
j[i] = 0;
}
}
}
recursivelyReplaceNullToZero(_json);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With