2016-09-23 61 views

回答

2

夫特2

FIRDatabase.database().reference().child("events").queryOrderedByChild("id").queryEqualToValue(4).observeSingleEventOfType(.Value, withBlock: {(Snap) in 
    if let snapDict = Snap.value as? [String:AnyObject]{ 
     for each in snapDict{ 
      print(each.0) // Will print out your node ID = 1 
      print(each.1) //Will print out your Dictionary inside that node. 
      } 

     } 

    }) 

夫特3

FIRDatabase.database().reference().child("events").queryOrdered(byChild: "id").queryEqual(toValue: 4).observeSingleEvent(of: .value, with: {(Snap) in 
     if let snapDict = Snap.value as? [String:AnyObject]{ 
      for each in snapDict{ 
       print(each.0) // Will print out your node ID = 1 
       print(each.1) //Will print out your Dictionary inside that node. 
      } 

     } 

    }) 
+0

接受此为答案,如果它解决了您的问题:)快乐编码 – Dravidian

+0

什么是安静的代码。它真的帮助了我。 非常感谢 – Aleksandar

1

可能会解决你的问题

[self.dbRef observeEventType:FIRDataEventTypeValue withBlock:^(FIRDataSnapshot * _Nonnull snapshot) { 
    if (![snapshot.value isKindOfClass:[NSNull class]]) { 
     NSArray *arrResponse = (NSArray *)snapshot.value; 

     NSPredicate *pred = [NSPredicate predicateWithFormat:@"id = %@", serchID]; 
     NSArray *arrSearchedVal = [arrResponse filteredArrayUsingPredicate:pred]; 
    } 
}]; 

NB: DBREF是你FIRDatabaseReference,这返回整个数据JSON。然后用您的搜索ID使用NSPredicate,您将得到您的结果。

enter image description here

enter image description here

编码愉快..

+0

WC ...很高兴为您提供帮助.. –