gpt4 book ai didi

java - equalTo ("value","key") 在 Firebase 中的用法?

转载 作者:搜寻专家 更新时间:2023-11-01 02:40:42 26 4
gpt4 key购买 nike

数据结构如下:

{
"list" : {
"-K4YlfoWHZqPyWONv68Y" : {
".priority" : -1.449077948445E12,
"date" : 1449077948445,
"id" : "0",
"name" : "Name_0"
},
"-K4YlfoWHZqPyWONv68Z" : {
".priority" : -1.449077948445E12,
"date" : 1449077948445,
"id" : "1",
"name" : "Name_1"
},
"-K4YlfoWHZqPyWONv68_" : {
".priority" : -1.449077948445E12,
"date" : 1449077948445,
"id" : "0",
"name" : "Name_2"
},
"-K4YlfoWHZqPyWONv68a" : {
".priority" : -1.449077948445E12,
"date" : 1449077948445,
"id" : "1",
"name" : "Name_3"
},
...
}

我只需要获取id为“0”的项目;

以下是有效的:

final Firebase ref = new Firebase("https://millezim-test.firebaseio.com/").child("list");

ref.orderByChild("id").equalTo("1").addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot d : dataSnapshot.getChildren()) {
Model m = d.getValue(Model.class);
}
}

@Override
public void onCancelled(FirebaseError firebaseError) {

}
});

但不是这个,为什么?

ref.equalTo("1","id").addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot d : dataSnapshot.getChildren()) {
Model m = d.getValue(Model.class);
}
}

@Override
public void onCancelled(FirebaseError firebaseError) {

}
});

我是否误解了 equalTo("value","key") 是在不重新排序的情况下使用的?

最佳答案

Firebase documentation for equalTo关于(可选)key 参数的说明:

The child key to start at, among the children with the previously specified priority. This argument is only allowed if ordering by priority.

由于您没有按优先级排序,因此您需要通过显式调用 orderByChild() 来指定 child 。

关于java - equalTo ("value","key") 在 Firebase 中的用法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34049941/

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