I'm currently having trouble getting the value from the firebase query below, I'm trying to return an image file from the if statement, but instead, it is returning 'undefined'. I know it is because the value is being returned in the nested firebase function rather the parent 'itemStatus' function.
function itemStatus(key) {
ref.child(key)
.once('value')
.then(function(snapshot) {
var value = snapshot.val();
//returns "true" or "false"
var status = value.status;
if (status == "true") {
return 'success.png';
} else {
...
}
});
//how do I get the values of my if statement here?
}
My question is, how do I return the value outside of the nested query?
I tried wrapping the firebase query in a function and then tried calling it outside but it still returned 'undefined' regardless but I feel I'm going wrong somewhere doing that. I've not had problems with nested functions before but this is really confusing me, I'm guessing it's because the firebase call is asynchronous and that is causing issues somehow but I'm really not sure. Any help would be much appreciated!