My FireBase structure is shown below:
I need to retrieve data from different FireBase tables, In order to append the data in a single html table, every FireBase table(node) is a column in my html table.
Is there a way to do this in one single query? Instead of writing it in a sloppy way like a 30 identical queries?
The only change between the all FireBase tables is the path in the middle:
var ref = firebase.database (). ref ("dailyT /Avg_Gain/" + desiredDate) .orderByChild ("Prefix")
var ref = firebase.database (). ref ("dailyT /Buy_Date/" + desiredDate) .orderByChild ("Prefix")
var ref = firebase.database (). ref ("dailyT /Buy_Price/" + desiredDate) .orderByChild ("Prefix")
Thank you very much.
var ref = firebase.database().ref("dailyT/" + Various tables + "+desiredDate).orderByChild("Prefix")) //.orderByChild("Prefix")
ref.once("value").then(function(snapshot) {
if(snapshot.exists()){
snapshot.forEach(function(childSnapshot) {
var val = childSnapshot.val();
console.log("Prefix: "+val.Prefix);
});
// Append to table code
}else{
//No such data in the firebase
}
});
You may retrieve first the keys of your root's child something like :
var keys = [];
var db = firebase.database();
db.ref().once('value', s => {
s.forEach(k=> {
keys.push(k.key); // result:[Avg_Gain, Buy_Date, Buy_Price...]
})
})
Then you may retrieve same desiredDate
data into above keys.
vals= [];
keys.forEach(k=>{
db.ref('dailyT/'+k+"/" +desiredDate).orderByChild("Prefix")
.once('value', snap=>{
if (snap.exists()) { vals.push(snap.value()) }
})
})
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.