鉴于下面的数据结构(从firebase导出):
{
"users" : {
"123456789" : {
"email" : "test@gmail.com",
"name" : "test",
"listings" : {
"adtitle" : {
"description" : "this is a description",
"skilltype" : "painter"
},
"adtitle2" : {
"description" : "this is a second description",
"skilltype" : "painter"
}
}
}
}
}
我想运行以下查询:
var ref = new Firebase("https://my.firebaseio.com/users");
ref.orderByChild("listings/adtitle/skilltype").equalTo("painter").on("child_added", function(snapshot) {
console.log(snapshot.key());
});
但在控制台上出现以下错误:
Error: Query.orderByChild failed: First argument was an invalid key: "listings/adtitle/skilltype". Firebase keys must be non-empty strings and can't contain ".", "#", "$", "/", "[", or "]").
谁能看到我哪里错了?我认为这是在firebase中查询嵌套数据的正确方法吗?
答案 0 :(得分:0)
查询更深层次的属性的能力是introduced in Firebase JavaScript SDK 2.3。如果您定位到Android或iOS,则会在这些SDK的2.4版本中引入该功能。
确保您使用的是该版本(或更新版本)。
请注意,我不认为这是一个答案,但问题反复出现(请参阅this one from yesterday),如果没有答案,我就无法标记副本。