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 get the same with the Firebase on method and get the value as:
snapshot.val()
I get the object, but keys with null values ββare removed, i.e. I got:
{"objects":[ {"type":"path", "originX":"center", "originY":"center","left":48.59, "top":132.5,"width":64.5, "height":173, "stroke":"#3f7cc4","strokeWidth":12 }]}
This causes me some weird problems, since I use Fabric.js , and this needs these values. Please, help!
EDIT / UPDATE (Hack)
I am currently using a weird HACK before storing an object in Firebase. I convert all null values ββto 0 . But I want to know a better way to do it.
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);
javascript object firebase
softvar
source share