I have a collection of objects stored in Google Firebase that I need to process and store in an array:
firebase.database().ref('trainingsets').once('value')
.then((snapshot) => {
var trainingSets: TrainingSet[] = [];
console.log(snapshot.val()); // Output 1
snapshot.forEach((child) => {
console.log("child=" + child); // Output 2
trainingSets.push(child);
});
console.log(trainingSets); // Output 3
this.trainingSets = trainingSets;
this.trainingSetsChanged.next(this.trainingSets.slice());
});
The model TrainingSet represents the structure of each object stored in Firebase:
export class TrainingSet {
/**
* Unique Identifier of this set
*/
id:number;
name:string;
type: string;
description: string;
}
Although my data is fetched successfully, I encounter some issues. While at Output 1 I observe an Object with two sub-objects containing the data, Output 2 displays empty objects, and Output 3 shows an array with elements named "V" that have unusual sub-items. I'm unsure about their nature.
If anyone can provide guidance on a more effective approach for this task, it would be greatly appreciated. I might not require an array if I could traverse the object tree accurately.