如何在不从firebase For ios获取值的情况下读取父节点名称?
我想用swift阅读如何在不从firebase For ios获取值的情况下读取父节点名称?,ios,swift,firebase,Ios,Swift,Firebase,我想用swift阅读餐厅名称汉堡王,就餐点 如何可能,有人能帮助我请这是我的最后一个项目需要在1周内提交请我失去了这个希望 只需使用下面的代码获取父节点名称 ref = Database.database().reference() ref?.child("Restaurants").observe(.childAdded, with: { (snapshot) in let rest = snapshot.value as? String // snapshot.key is
餐厅
名称汉堡王
,就餐点
如何可能,有人能帮助我请这是我的最后一个项目需要在1周内提交请我失去了这个希望
只需使用下面的代码获取父节点名称
ref = Database.database().reference()
ref?.child("Restaurants").observe(.childAdded, with: { (snapshot) in
let rest = snapshot.value as? String
// snapshot.key is give you parent node name
print(snapshot.key)
}
})
要仅获取餐厅名称,请使用以下代码
dbReference = Database.database().reference()
dbReference?.child("Restaurants").observeSingleEvent(of: .value, with: {(snapshot) in
for rest in snapshot.children.allObjects as! [DataSnapshot] {
print("Restaurant Name:\(rest.key)")
}
})
dbReference = Database.database().reference()
dbReference?.child("Restaurants").observeSingleEvent(of: .value, with: {(snapshot) in
for rest in snapshot.children.allObjects as! [DataSnapshot] {
print("Restaurant Data:\(rest)")
}
})
要使用StoryboardId传递所有数据,请使用下面的代码
dbReference = Database.database().reference()
dbReference?.child("Restaurants").observeSingleEvent(of: .value, with: {(snapshot) in
for rest in snapshot.children.allObjects as! [DataSnapshot] {
print("Restaurant Name:\(rest.key)")
}
})
dbReference = Database.database().reference()
dbReference?.child("Restaurants").observeSingleEvent(of: .value, with: {(snapshot) in
for rest in snapshot.children.allObjects as! [DataSnapshot] {
print("Restaurant Data:\(rest)")
}
})
把这个放在你的口袋里
并在destinationController中声明数据变量,如下所示:
var data = [DataSnapshot]()
你必须像这样从didselectRowAt进行检查
performSegue(withIdentifier: "segue", sender: self)
您可以通过以下功能传递所选项目的数据
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
let index = CategorytableView.indexPathForSelectedRow
let indexNumber = index?.row
print(indexNumber!)
let VC = segue.destination as! DestinationVC
VC.data = [rest] . //You can pass here entire data of selected row.
}
到目前为止,您尝试了什么?参考
餐厅
节点,然后执行firebase查询。在您的问题标题中,没有从firebase For ios获取值
意味着什么?我已经完成了此代码,但它返回nil valueChange。childAdded
到。键入值
以获取整个值。很高兴这样做听我说,兄弟!快乐地编码并抱怨你的项目,因为“我的一天”向你竖起大拇指。childAdded
不是获取所有数据的正确方式。你们会一个接一个地得到数据,你们怎么知道它什么时候完成的?伙计们,我怎么用Javascript得到完全相同的结果?