搜索儿童价值Firebase / Swift [英] Searching through child values Firebase / Swift
问题描述
我的数据库有这样排序的值:
用户
UID
用户名
电子邮件
我想要实现一个朋友添加系统,您可以搜索用户名或电子邮件,它可以让你添加该人。
我可以通过使用
< $ {$ b $ print(snapshot.value)$ b中的queryEqual(toValue:input).observeSingleEvent(of:.value){(snapshot:FIRDataSnapshot)code> REF_USERS.queryOrdered(byChild:displayname
$ p
$ b $ p我得到了用户的整个字典,但是我遇到了一个问题, UID。
snapshot.key给我用户。
如何获取UID值使用用户名/电子邮件查找用户字典后的字典?
解决方案当您对Firebase数据库执行查询时,将潜在的多个结果。所以快照包含了这些结果的列表。即使只有一个结果,快照也会包含一个结果列表。
let query = REF_USERS.queryOrdered(在$ {
中为快照.children中的子元素{
print()}中的queryEqual(toValue:input)
query.observeSingleEvent(of:.value){(snapshot:FIRDataSnapshot) (child.key)
}
}
另见:
- 在query-by-order / 37635385#37635385> firebase中的queryOrderBy访问键 queryOrderBy中的Firebase访问键 Firebase获取数据的顺序
My database has values sorted like this :
Users
UID
Username
Email
I'm wanting to implement a friend adding system where you search for either a username or email and it lets you add the person.
I'm able to locate users by using
REF_USERS.queryOrdered(byChild: "displayname").queryEqual(toValue: input).observeSingleEvent(of: .value) { (snapshot: FIRDataSnapshot) in {
print(snapshot.value)
}
With that I get the user's entire dictionary, but I'm having an issue grabbing the UID.
snapshot.key gives me "Users".
How can I grab the UID value out of the dictionary after finding the user's dictionary with either their username/email?
When you execute a query against the Firebase Database, there will potentially be multiple results. So the snapshot contains a list of those results. Even if there is only a single result, the snapshot will contain a list of one result.
let query = REF_USERS.queryOrdered(byChild: "displayname").queryEqual(toValue: input)
query.observeSingleEvent(of: .value) { (snapshot: FIRDataSnapshot) in {
for child in snapshot.children {
print(child.key)
}
}
Also see:
- Firebase snapshot.key not returning actual key?
- Firebase access keys in queryOrderBy
- Firebase access keys in queryOrderBy
- Firebase getting data in order
这篇关于搜索儿童价值Firebase / Swift的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!