快速检索多个firebase节点

时间:2018-05-27 05:29:44

标签: swift firebase firebase-realtime-database

我从下面的firebase后端检索数据。我的JSON结构有2个儿童笔记来自我的理解随着我视图中的代码加载,我可以访问用户节点,我可以打印“电子邮件”& “提供者” -

但是,我的主要目标是实际访问“planits”节点并获取“图像”和“ “planit”细节。我只是坚持一种实现它的方法。我将不胜感激所提供的任何和所有帮助。谢谢!

enter image description here

覆盖func viewDidLoad(){

    super.viewDidLoad()

    ref = Database.database().reference()
    refHandle = ref.observe(DataEventType.value, with: { (snapshot) in
        let dataDict = snapshot.value as! [String: AnyObject]

        print(dataDict)

    })


    let userID = Auth.auth().currentUser?.uid


    ref.child("users").child(userID!).observeSingleEvent(of: .value, with: { (snapshot) in
         //Get user value
         if snapshot.exists() == true {

            for child in snapshot.children {

                let value = snapshot.value as? NSDictionary
                let EmailString = value!["email"] as! String

                self.userEmail.append(EmailString)
                print(self.userEmail)

// BELOW IS MY FAILED ATTEMPT AT ACCESSING THE 'planits' node - Nothing Prints

                let image = value!["images"] as! String
                print(image)


        }
    }
    }) { (error) in
        print(error.localizedDescription)
    }

0 个答案:

没有答案