【问题标题】:Returning newly created key after .push firebase在 .push firebase 之后返回新创建的密钥
【发布时间】:2016-12-05 21:14:44
【问题描述】:

我是 Firebase 的新手,但我需要在将 prop 推送到 Firebase 后 60 秒更新它。 .push() 成功后如何获取 Firebase 创建的动态密钥?

function storeData(val){
$scope.ref = new Firebase('...')

$scope.ref.push({'va1': val, 'status': 'active' });
//after push give me back the newly created key string for that item only
}

【问题讨论】:

    标签: angularjs json firebase firebase-realtime-database


    【解决方案1】:

    传递push()末尾的key属性。

    function storeData(val){
      const dataRef = new Firebase('...')
      const key = dataRef.push({'va1': val, 'status': 'active' }).key;
    }  
    // Before returning the key value, it pushes the data to the database. 
    

    【讨论】:

      【解决方案2】:

      我想通了。我发现这很有魅力

      $scope.ref.limitToLast(1).on("child_added", function(snapshot) {
      console.log(snapshot.key());
      })
      

      【讨论】:

        猜你喜欢
        • 2016-02-07
        • 2023-03-04
        • 2018-11-26
        • 2017-10-21
        • 1970-01-01
        • 1970-01-01
        • 2016-04-19
        • 2018-01-02
        • 2018-03-04
        相关资源
        最近更新 更多