2016-11-10 111 views
1

我想使用Swift加載Firebase上的Modern類型的所有圖像。我該怎麼做?過濾Firebase數據Swift

這裏是我的數據模型:

"arts" : { 
    "-KW5plrmDFMGa9pUlTg3" : { 
    "description" : "Title ", 
    "height" : 25.36023, 
    "imageUrl" : "https://firebasestorage.googleapis.com/v0/b/medici-b6f69.appspot.com/o/Arts%2FJ7U039FN6YckdbQ7KgeJKuZDO2I3%2F26DDC192-C081-4588-BD52-2841FA3EF507?alt=media&token=e828936c-5341-4429-94e9-c3aefa81769b", 
    "postDate" : 1478657252917, 
    "title" : "Title ", 
    "type" : "Modern", 
    "width" : 25.99424 
} 

這裏是我的嘗試。但它不起作用。

DataBase.child("arts").queryOrdered(byChild: "Modern").observe(.value) { (snapshot: FIRDataSnapshot) in 
    self.posts = [] 

    if let snapshot = snapshot.children.allObjects as? [FIRDataSnapshot] { 
     print("SNAPSHOT: \(snapshot)") 

     for snap in snapshot { 
      if let postDict = snap.value as? Dictionary<String, AnyObject> { 
       let key = snap.key 
       let post = ProfileArtModel(key: key, artData: postDict) 
       self.posts.insert(post, at: 0) 
      } 
     } 
    } 
    self.tableView.reloadData() 
} 
+0

請遠離火源基地後滿樹,我看不到樹藝術與現代。 –

+0

更改(byChild:「mordern」) - >(byChild:「modern」) –

+0

我剛剛編輯了三個@TejasArdeshna。它仍然不會工作薩沙。謝謝 – kurbs

回答

0

嘗試: -

DataBase.child("arts").queryOrdered(byChild: "type").queryEqual(toValue : "Modern").observe(.value) { (snapshot: FIRDataSnapshot) in 
self.posts = [] 

if let snapshot = snapshot.children.allObjects as? [FIRDataSnapshot] { 
    print("SNAPSHOT: \(snapshot)") 

    for snap in snapshot { 
     if let postDict = snap.value as? Dictionary<String, AnyObject> { 
      let key = snap.key 
      let post = ProfileArtModel(key: key, artData: postDict) 
      self.posts.insert(post, at: 0) 
      self.tableView.reloadData() 
     } 
    } 
    } 
} 
+0

這是否解決了你的問題? – Dravidian