Javascript Firebase API和Vue.JS通过特定属性值获取多个元素
如何获取Firebase(子)中具有相同类别ID的所有元素Javascript Firebase API和Vue.JS通过特定属性值获取多个元素,javascript,firebase,firebase-realtime-database,vue.js,promise,Javascript,Firebase,Firebase Realtime Database,Vue.js,Promise,如何获取Firebase(子)中具有相同类别ID的所有元素 getbyCateg: function(myCateg) { var items = []; FireBase.database().ref('product') .orderByChild('category') .equalTo(myCateg) .once("value", function(snapshot) { v
getbyCateg: function(myCateg) {
var items = [];
FireBase.database().ref('product')
.orderByChild('category')
.equalTo(myCateg)
.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("There is nothing of this category");
}
});
return (items);
。一旦允许访问具有良好类别ID的第一个元素,那么其他元素呢?我想创建一个包含所有这些元素的数组
谢谢 在不了解您的数据结构的情况下,我不确定您真正的问题是什么。但也许这就是一切,你需要:
getbyCateg: function(myCateg) {
var items = [];
FireBase.database().ref('product')
.orderByChild('category')
.equalTo(myCateg)
.once("value", function(snapshot) {
snapshot.forEach(function (childSnapshot) {
key = childSnapshot.key;
if (key) {
// also, try this items.push(key.toString()) instead of next line
items.push(FireBase.database().ref('product').child(key).toString());
} else {
console.log("There is nothing of this category");
}
});
});
return (items);
}