equalTo("value","key") 在 Firebase 中的用法?
Usage of equalTo("value","key") in Firebase?
这是以下数据结构:
{
"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
这是以下数据结构:
{
"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()
.