2017-02-21 69 views
0
cards 

    cars 
    -- idcars 
     -- type: 
     -- age: 
     -- user: iduser 

    users 
    -- iduser 
    -- username 
    -- usermail 


    ads 
    -- iduser 
    -- ads1 : idcars 
    -- ads2 : idcars 

有了這種結構,可以如何爲用戶檢索所有廣告以及他們自己的數據?來自2個節點的Firebase查詢

例子:

ads1: 
type: golf 
age:2 

我與火力地堡

回答

0

完全新這應該是你需要得到認證的用戶是什麼,然後你可以使用這個模型只是檢索整個ads分支濾波通過它有每個人的詳細信息2012年(如果你想)

let userID = FIRAuth.auth()?.currentUser?.uid 
ref.child("ads").child(userID!).observeSingleEvent(of: .value, with: { (snapshot) in 

    // Get user value 
    let value = snapshot.value as? NSDictionary // This gets the whole ad branch with all the users ad data 
    let adsValue = value?["ads1"] as? String ?? "" // This is the specific value of 'ads1' node 

    // ... 
    }) { (error) in 
    print(error.localizedDescription) 
} 
+0

thnx但目前我只收回ads1和idcars,並非所有的汽車數據... – HaVaNa7

+0

你需要做一個for循環,循環遍歷每個節點並獲取每個用戶的數據 – RyanM

0

也許這樣,

得到那麼用戶ID把它放在ref.child(yourString)

ref = FIRDatabase.database().reference() 
    ref.child("iduser").observeSingleEvent(of: FIRDataEventType.value, with: { (snapshot) in })