无法从firebase数据库获取密钥

时间:2017-02-14 13:10:14

标签: ios firebase swift2 firebase-realtime-database

我一直在思考学生程序员生活中最长的一段时间。我想知道

我使用autoChildId添加了密钥。

  1. 如何从firebase数据库swift 2获取密钥?我知道如何使用.getKeys()

  2. 从Android获取
  3. 我最好的朋友Google教我使用allKeys。然而,我现在处于绝望的边缘,因为我收到了以下信息:我们与.allKeys的关系总是会失败(见下图)。 Haish ...

  4. Evidence of our relationship status right now

    1. 我需要这个才能将Firebase数据库中的数据显示到我的tableview中。我相信这是一个空表的问题,就像我的心脏对我的项目一样。没有心。
    2. 以下是我的firebase数据库的样子:

      My firebase database

      这是我的代码:

      func findPlaceToEat(){
          print("inside findPlaceToEat()")
      
          print("Plan price level")
          print(planPriceLevel)
          print("End of price level")
      
          ref = FIRDatabase.database().reference()
      
          ref.child("places_detail").child("price_level").child(planPriceLevel).observeEventType(.ChildAdded, withBlock:{
              (snapshot) in
      
              if let dictionary = snapshot.value?.allKeys! as? [String: AnyObject]{
                  let PlaceObj = placeObj(place_name: dictionary["place_name"] as! String, place_type: dictionary["place_type"] as! String, price_range: dictionary["price_range"] as! String, vegan_type:dictionary["vegan_type"] as! String , website: dictionary["website"] as! String)
                  print("Whatever")
      
                  print(PlaceObj);
                  //self.tableView.reloadData()
      
              }
              }, withCancelBlock: nil)
      }
      

3 个答案:

答案 0 :(得分:1)

从快照中获取密钥

snapshot.key

答案 1 :(得分:0)

我为我的项目找到了一个解决方法,大家请为我的讲师不要看到这个。 :

我所做的是在保存按钮内我从数据库中检索值,然后将其保存回Firebase数据库。

SELECT 
    SUM(st.row_count)
FROM 
    sys.dm_db_partition_stats st
WHERE 
    object_name(object_id) = '{TableName}' 
    AND (index_id < 2)

答案 2 :(得分:0)

您需要定义查询orderbykey,如bellow:

  this.afd.list('/yourItems/', {query:{orderByKey :true}}).subscribe((elements) => {

            elements.map(element=>{
              console.log(element.$key);

            })

        });
相关问题