首页 > 解决方案 > 使用 Firebase 中的多个值检索 id

问题描述

我想检索项目 ID 并使用项目其他值将其设置为变量。根据这张图片(“get id where Brand="Manchee" and ItemName="Cream Cracker" and SubCategory="100g" ")如何写这个函数

在此处输入图像描述

标签: firebase

解决方案


在这里您可以尝试此解决方案。我认为您想查询数据库,以便您可以根据变量值对数据库进行查询。只需在此查询中传递键和值,您就可以将所有数据驻留在表中属于此查询。

  var ref = firebase.database().ref("items");
    ref.orderByChild("itemName").equalTo('Manchee').once("value", (items : any)=> {
      console.log(items.key);
      console.log(items.val());
      let itemArray: any = [];

      items.forEach((item) => {
        itemArray.push({
          key: item.key,

        });
      });
      this.items = itemArray;
      console.log("Prescription Data: ", itemArray);
    });

推荐阅读