Firebase获得儿童ID快捷的ios [英] Firebase get child ID swift ios

查看:163
本文介绍了Firebase获得儿童ID快捷的ios的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Firebase看起来像这样。 Bellow Active_Orders 根据它们的 UID childs >(用户ID)。





这是我的代码无论名字是什么,孩子的ID。但它似乎并没有工作。什么是正确的方式来获取子ID ?谢谢

  databaseRef.child(Active_Orders)。 b $ b //获取customerUID 
让customerUID = snapshot.value!.objectForKey(username)as!String
self.setText(customerUID,value:customerUID)
< code $ <$ $ p

解决方案

很难从你的问题中确切地知道你在做什么,给你你需要的清单?

  databaseRef.child(Active_Orders)。observeEventOfType(.Value,withBlock:{ )in 
if result = snapshot.children.allObjects as?[FIRDataSnapshot] {
for child {
var orderID = child.key as!String
print(orderID )
}
}
})

应该迭代Active_O中的所有子项rders并打印出他们的关键值(这似乎是你想要打印的)。

My Firebase looks like this. Bellow Active_Orders it appear childs with different names depending on their UID(user ID).

And this is my code to get the child's ID no matter what the name is. But it does not seem to work at all. Whats the proper way to get the child ID? Thanks

databaseRef.child("Active_Orders").observeEventType(FIRDataEventType.Value, withBlock: {
                    snapshot in
                //Get customerUID
                let customerUID = snapshot.value!.objectForKey("username") as! String
                self.setText("customerUID", value: customerUID)

解决方案

It is hard to tell from your question exactly what you are doing, but does this get you the list you need?

databaseRef.child("Active_Orders").observeEventOfType(.Value, withBlock: { (snapshot) in 
    if let result = snapshot.children.allObjects as? [FIRDataSnapshot] {
        for child in result {
            var orderID = child.key as! String
            print(orderID)
        }
    }
})

I believe this block should iterate over all the children that are inside "Active_Orders" and print out their key value (which seems to be what you are trying to print).

这篇关于Firebase获得儿童ID快捷的ios的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆