如何从 firebase 中获取子 子节点的子?现在我使用此代码来获取孩子,但我无法从第一个和第二个孩子获得图片:
(1<<5) and (1>>5)
我明白我在我的功能中遗漏了一些东西,但我错过了什么我无法理解。 还有我的firebase结构:
var images = [String]()
var images2 = [String]()
override func viewDidLoad() {
super.viewDidLoad()
nameAddressRef = Database.database().reference(withPath: "Студии")
loadImages()
}
func loadImages() {
nameAddressRef.observe(DataEventType.value, with: { (snapshot) in
var newImage = [String]()
var newImage1 = [String]()
for child in snapshot.children {
let snap = child as! DataSnapshot
let imageSnap = snap.childSnapshot(forPath: "Images")
let dict = imageSnap.value as! [String: AnyObject]
let url1 = dict["image1"] as! String
let url2 = dict["image2"] as! String
newImage.append(url1)
newImage1.append(url2)
}
self.images = newImage
self.images2 = newImage1
})
}
}
extension ViewController: UITableViewDataSource, UITableViewDelegate {
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! CategoryRow
cell.nameLabel.text = nameAddress[indexPath.section].name
let array = [images[indexPath.section],
images2[indexPath.section]]
cell.images = array.filter({ !($0.isEmpty) })
return cell
}
}
感谢您的帮助!
答案 0 :(得分:2)
试试这个: -
func loadImages (){
Database.database().reference(withPath:
"Студии").child("Дубаи").observe(.value, with: { (snapShot) in
if snapShot.exists() {
let array:NSArray = snapShot.children.allObjects as NSArray
for child in array {
let snap = child as! DataSnapshot
if snap.value is NSDictionary {
let data:NSDictionary = snap.value as! NSDictionary
if let dict = data.value(forKey: "Images") {
let dictImage:NSDictionary = dict as!
NSDictionary
if let image = dictImage["image1"] {
print(image)
}
}
}
// newImage1.append(url2)
}
}
})
}
答案 1 :(得分:1)
Create Table MyTbl
(
Mon Int,
Tue Int,
Weds Int,
Thurs Int,
Fri Int,
Sat Int,
Sun Int,
Total As (Mon + Tue + Weds + Thurs + Fri + Sat + Sun)
);
下没有Images
,因此循环不匹配。
你想要在JSON中听一级以下:
Студии