返回了firebase父id而不是子id
我是firebase的新手,我第一次使用ionic开发聊天应用程序。我有一个结构类似的数据库,如下所示返回了firebase父id而不是子id,firebase,ionic-framework,firebase-realtime-database,Firebase,Ionic Framework,Firebase Realtime Database,我是firebase的新手,我第一次使用ionic开发聊天应用程序。我有一个结构类似的数据库,如下所示 tutors: "Ben Clarke": email:"ben@yahoo.com" name: ben clarke "James Gall": email:james@yahoo.com name: james gal 我正试图通过电子邮件获得导师的身份。我已尝试使用我在此处和firebase doc上找到的指南来执行此操作: `firebase.datab
tutors:
"Ben Clarke":
email:"ben@yahoo.com"
name: ben clarke
"James Gall":
email:james@yahoo.com
name: james gal
我正试图通过电子邮件获得导师的身份。我已尝试使用我在此处和firebase doc上找到的指南来执行此操作:
`firebase.database().ref('tutors').orderByChild('email').equalTo(this.myTutor)
.once('value')
.then(snapshot => {
var records = snapshot.key;
var chilkkey= snapshot.val();
this.tutorID=records;
this. uid = chilkkey;
})
`我希望结果给我“Ben Clarke”孩子id,但它返回“tutors”,这是家长id。请了解我做错了什么。谢谢当您对Firebase数据库执行查询时,可能会有多个结果。因此,快照包含这些结果的列表。即使只有一个结果,快照也将包含一个结果列表 如果在快照上请求密钥,则该密钥是最初运行查询的位置的密钥。要获取查询匹配的特定子项的键,需要循环查询结果:
firebase.database().ref('tutors').orderByChild('email').equalTo(this.myTutor)
.once('value')
.then(snapshot => {
snapshot.forEach(function(child) {
console.log(child.key);
});
})
很高兴听到。如果我的答案有用,请单击其左侧的向上投票按钮。如果它回答了您的问题,请单击复选标记接受它。这样别人就知道你得到了足够的帮助。