Tuesday 6 June 2017

Get data from nested foreach

I'm building an app using firebase and Node.js. I need to get data from nested foreach. How to do it correctly?

exports.userParty = function (userInfo, cb) {

var userID = userInfo.userID;
var clubID = userInfo.clubID;

var refUserParty = ref.child(userID).child('my_party_id');

var party = {};

refUserParty.orderByValue().once("value", function (snapshot) {

    var party = {};

    snapshot.forEach(function (partyID) {

        var refParty = dbb.ref('clubs').child(clubID).child('party').child(partyID.val());

        refParty.once('value', function (partyBody) {
            party[partyID.val()] = partyBody.val();
            //console.log(party);
        });

    });
    cb(party); // {}

});

};



via Roman Melnyk

No comments:

Post a Comment