如何从Firebase中检索另一个孩子中的孩子?

时间:2017-01-19 09:06:25

标签: ios firebase firebase-realtime-database

我正在尝试检索medicine子项,如果其created_on时间等于指定时间。这是我的代码:

func loadDataFromFirebase(){
 let tym = summary?.created_on
databaseRef = FIRDatabase.database().reference().child("medical_details")
databaseRef.queryOrderedByChild("created_on").queryEqualToValue(tym).observeSingleEventOfType(.ChildAdded, withBlock: { snapshot in
        for item in snapshot.children {

            print(snapshot)
        }
    })

它显示了这样的快照:

Snap (-KZQxDyOJ9nLyiK_l3lT) {
comments = hhf;
"created_on" = "Dec 20, 2016 4:49:11 PM";
medicine =     {
    "-KZQxDyUtdydQRdpWKNN" =         {
        dosage = " 10/300mg";
        frequency = 5;
        interval = 6;
        "number_of_tablets" = 4;
        reminder = Notification;
        tablet = "Vicodin(Hydrocodone/Acetaminophen)";
    };
    "-KZQxDy_AlMzR_L36y-R" =         {
        dosage = " 10mg";
        frequency = 6;
        interval = 5;
        "number_of_tablets" = 2;
        reminder = Notification;
        tablet = Methadone;
    };
};
"pain_level" = 2;
remedies = "Drinking Water";
"user_id" = QyKCJl3gTIa1Pl7j9GHpvnVU6Fo2;
}

我的问题是如果created_on等于所选时间,如何单独检索medicine个节点?

0 个答案:

没有答案