面对问题,获取在forEach
操作下推送的数组列表,不能在forEach
之外进行访问。 我无法在forEach操作后获取数组值(instaprofile)
var uid = 132456;
var instaprofile = [];
var ref = firebase.database().ref("InstaAccounts");
ref.orderByChild("IgrowthId").equalTo(uid).once("value")
.then(function (snapshot) {
snapshot.forEach(function (childsnap) {
var igid = parseInt(childsnap.val().IgramuserId);
var inprof = firebase.database().ref("InstaProfile");
inprof.orderByChild("Userid").equalTo(igid).once("value")
.then(function (inprofsnap) {
var data = inprofsnap.val()[Object.keys(inprofsnap.val())[0]];
instaprofile.push(data);
})
})
console.log(instaprofile);
});