Looking to retrieve all Firebase elements (child) with the same category ID?
fetchByCategory: function(myCategory) {
var items = [];
FireBase.database().ref('product')
.orderByChild('category')
.equalTo(myCategory)
.once("value", function(snapshot) {
var key;
snapshot.forEach(function (childSnapshot) {
key = childSnapshot.key;
return true;
});
if (key) {
items.push(FireBase.database().ref('product').child(key).toString());
} else {
console.log("No elements found in this category");
}
});
return (items);
The use of `.once` retrieves the first element matching the category ID. How can I obtain an array of all these elements?
Thank you!