gpt4 book ai didi

java - 如何过滤firebase中的嵌套数据?

转载 作者:行者123 更新时间:2023-12-02 11:05:34 31 4
gpt4 key购买 nike

我在 firebase 数据库中有以下数据结构。

tripPackages
-LCoHHZWL-NTLmJKDILV
50180557210016753
creationDate:
farmerID:
id:
itemState:
noOfItems:
noOfSoldItems:
totalAmount:
tripId:
tvoID:
vegetableName:
vid
weight:

节点 trippackages 包含包含包裹的行程,其中 -LCoHHZWL-NTLmJKDILV 是行程 ID,50180557210016753 是包裹 ID。现在,我想过滤具有特定 itemState 的所有旅行包(例如 IN_TRASIT)。

我相信这段代码应该这样做:

firebaseDatabase.getReference().child("tripPackages").orderByChild("itemState").equalTo("IN_TRANSIT");

其中子 itemState 的值是我的 POJO 中的枚举,但我无法达到预期的结果。

POJO中child的嵌套位置级别或者child的值的类型有关系吗?

当使用 orderByChild 的子项的嵌套位置级别为 2 并且子项的值为 String 时,我能够成功过滤类似数据结构中的数据。

最佳答案

Does the nested location level of child or type of the value of child in POJO has anything to do with it?

是的,有影响。您有这个数据库:

tripPackages  
-LCoHHZWL-NTLmJKDILV
50180557210016753
itemState: IN_TRANSIT

为了能够根据 itemState 的值进行过滤,请尝试以下操作:

firebaseDatabase.getReference().child("tripPackages").child("-LCoHHZWL-NTLmJKDILV").orderByChild("itemState").equalTo("IN_TRANSIT");

您需要添加行程ID,以便能够根据itemState过滤数据

关于java - 如何过滤firebase中的嵌套数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50998834/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com