I am struggling with a broken CodePen where I am trying to retrieve information of an object from another Firebase Ref using the object's key or id...
I have two Firebase Refs: The content
[
{
"name": "objecta",
".key": "objecta"
},
{
"name": "objectb",
".key": "objectb"
},
{
"name": "objectc",
".key": "objectc"
}
]
and the Related that lists the object by key and then the key of the ones that are related to that item.
[
{
"objectc": true,
".key": "objectb"
}
]
I am attempting to navigate through the relatedRef by key with this code:
var theKey = "objectb"
function getDiscoverBarContent(key, cb) {
relatedRef.child(key).on("child_added", snap => {
let relateRef = relatedRef.child(snap.key);
relateRef.once("value", cb);
console.log('relate:' + relateRef)
});
}
then obtain the data of the related object and display it in the console:
getDiscoverBarContent(theKey, snap => {
var snapVal = snap.val();
console.log(snapVal)
});
However, it is currently returning null instead of the desired object info in contentRef referenced in the relatedRef...any suggestions on how to fix this?