Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/463.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Firebase API和Vue.JS通过特定属性值获取多个元素_Javascript_Firebase_Firebase Realtime Database_Vue.js_Promise - Fatal编程技术网

Javascript Firebase API和Vue.JS通过特定属性值获取多个元素

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

如何获取Firebase(子)中具有相同类别ID的所有元素

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);
}