从Firebase查询阵列(React Native) [英] Querying array from Firebase (React Native)

查看:46
本文介绍了从Firebase查询阵列(React Native)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是React-native和Firebase的新手,我正在构建一个应用程序.我偶然发现了在Firebase中使用数组"的问题(我知道Firebase无法与数组一起使用),但是我想知道是否有某种方法可以检索此数据.

I'm new to react-native and firebase, and I am building an app. I stumble upon a problem using "array" in firebase (i know that firebase doesn't work with array), but I want to know if there is some way to retrieve this data.

这是我在服务器中拥有的数据,我想获取所有带有产品"id"(红色)的购买商品

This is the data I have in the server, and I want to get all the purchases that have the product "id" (in red)

我尝试使用下面的代码和一些变体,但未成功,返回null

I tried to use the code below and some variants but no success, returns null

firebase.database().ref('purchases').orderByChild("products/id")
.equalTo("-Lgida0VKuZZ6V7K0LkH").on('value', function (rawPurchases)

我想知道是否有一种获取此信息的方法.

I want to know if there is a way to get this information.

谢谢.

推荐答案

var scoresRef = firebase.database().ref("purchases");
scoresRef.orderByChild("products").on("value", function(snapshot) {
  snapshot.forEach(function(data) {
    console.log("The " + data.id + " data is " + data.val());
  });
});

尝试此方法并查看更多

try this method and review more here

这篇关于从Firebase查询阵列(React Native)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆