[英]Get data from Firebase db, comes back without key value
I am retrieving data from Firebase db using REST call. 我正在使用REST调用从Firebase数据库检索数据。 So i have a data looking like this
所以我有一个看起来像这样的数据
user
{
123456:
{
Email: "test@hotmail.com",
Password: "John Doe"
}
654321:
{
Email: "test2@hotmail.com",
Password: "Jane Doe"
}
}
The query I used is 我使用的查询是
firebaseurl/user.json?orderBy="Email"&equalTo="test@hotmail.com"
Is it possible if I query without the key value 123456
being retrieve? 如果查询没有检索到键值
123456
是否可以? Because whenever I try to use the data, for instance console.log(user.Email)
, I am getting undefined. 因为每当我尝试使用数据时,例如
console.log(user.Email)
,我都变得不确定。 But when I do it like console.log(user[123456].Email)
then will I get the result I desire. 但是,当我像
console.log(user[123456].Email)
这样操作时,我会得到我想要的结果。
May I know if there's a way to do it? 我可以知道是否有办法吗? Or a way to access to the child element without
user[keyvalue]
. 或者一种无需
user[keyvalue]
即可访问子元素的方法。
As it is expected only single record in return you can use: const user = obj[Object.keys(rslt)[0]]
可以预期,只有
const user = obj[Object.keys(rslt)[0]]
记录可以返回: const user = obj[Object.keys(rslt)[0]]
Or you can loop over the keys 或者您可以循环浏览按键
const usersArr = Object.keys(rslt).map(usr => {
... manipulate usr
return usr
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.