如何在Firebase中检索数据的名称

时间:2019-06-20 16:21:49

标签: swift firebase

我不确定“数据名称”是否是正确的调用方式,但这是我的问题:

我有一张这样的桌子

enter image description here

我想创建2个包含ID(0001, 0040)和Date(13-9-2017)的数组。

因为ID是自动生成的,所以我不知道如何查询

我尝试过的事情:

func retrievingPresciptionID(){
        let userID = appDelegate.userIDFirebase
        Database
            .database()
            .reference()
            .child("UserInformation")
            .child(userID)
            .child("prescriptionID")
            .observeSingleEvent(of: .value, with: {snapshot in
                if snapshot.exists(){
                    for id in snapshot.children {
                        self.prescriptionID.append((id as AnyObject).key)
                    }
                    print(self.prescriptionID)
                }else{
                    print("snapshot failed")
                }
            })
    }

它打印了snapshot failed

1 个答案:

答案 0 :(得分:0)

假设我们获得了处方ID的字典。

for prescription in prescriptionIDs { 
  IDArray.append(prescription.key)
  dateArray.append(prescription.value) 
}

问题是您无法让字典创建两个数组。找到丢失的节点。