خرید بک لینک

Vote count: 0

Just wanted to run this by some experts and get their thoughts on it. The way I am doing it just feels kinda hacky.

Here is my code:: Basically I find the Groups that the user is a Member of, then search for the group(s). As you can see I run a for loop that returns the object of each different group. That all works, but the problem is it seems like a lot of querying, and the callback function for some reason runs before the code is done executing.

var query = firebaseApp.database().ref().child('members').orderByChild('uid').equalTo(testUID);  
        query.once('value').then(function(snapshot) {
        snapshot.forEach(function(childSnapshot) {
        userObject = childSnapshot.val() 
        userGroups = userObject.groups.groupID

        console.log("User Groups==")
        console.log(userGroups)

        pullGroupInfo(
          function(){
            console.log("###########@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@")
          }

          );

        });  
    // end of get groups quer   
});


function pullGroupInfo(callback) {
    for(var i = 0; i < userGroups.length; i++) {
        /* do some stuff */ 

         var query = firebaseApp.database().ref().child('groups').orderByChild('id').equalTo(userGroups[i]);  
        query.once('value').then(function(snapshot) {
        snapshot.forEach(function(childSnapshot) {
          console.log("=")
          console.log(childSnapshot.val())
          groups.push(childSnapshot.val())

        });  

      });

    }
    callback();
}

Here is my json in case it is needed:

{
  "groups" : {
    "-KO0C5FdTWisnc4i9xxM" : {
      "id" : "jkdjsneind",
      "members" : {
        "General" : true,
        "TechChat" : true
      },
      "name" : "joe",
      "type" : "private"
    },
    "-KODDD0C5FdTWisnc4i9xxM" : {
      "id" : "jkdjfbdkbfj",
      "members" : {
        "General" : true,
        "TechChat" : true
      },
      "name" : "jack",
      "type" : "private"
    },
    "-KODDD0C5FdTWisnc4i9xxMxx2" : {
      "id" : "dfdsfds",
      "members" : {
        "General" : true,
        "TechChat" : true
      },
      "name" : "bigcat",
      "type" : "private"
    },
    "dicky" : "d",
    "ggg" : "gg"
  },
  "members" : {
    "-KO0C5FdTWisnc4i9xxM" : {
      "ageRange" : "18-20",
      "college" : "",
      "dob" : "",
      "firstname" : "joe",
      "friends" : {
        "UserID1" : true,
        "UserID2" : true,
        "UserID3" : true
      },
      "groups" : {
        "groupID" : [ "jkdjfbdkbfj", "jkdjsneind" ]
      },
      "lastname" : "caraccio",
      "name" : "joe",
      "pendingFriends" : {
        "UserID4" : true
      },
      "uid" : "6hOnKHBdkMWOaRFKiXyxLkU9lO33"

  }

}

Any Help would be great!

asked 42 secs ago

برچسب: is there a god,is there a nascar race today,is there a full moon tonight,is there anything at the end of suicide squad,is there any deal,is there anybody out there,is there a cure for aids,is there a cubs game today,is there a holiday today,is there a cure for cancer, نویسنده: استخدام کار تاريخ: سه شنبه 26 مرداد 1395 ساعت: 10:21

صفحه بندی