如何处理Firebase创建的生成密钥?

时间:2017-02-05 05:53:21

标签: angularjs json firebase ionic-framework firebase-realtime-database

我在添加新记录时需要帮助,当时Firebase会创建一个系统生成的密钥(请查看下面的图片),我在阅读JSON对象时遇到了麻烦。请建议我如何阅读所有节点数据。

json with key

或访问该系统生成的任何替代方法?

1 个答案:

答案 0 :(得分:0)

我假设您使用Ionicframework 1,忘记密钥。您可以使用angular.forEach方法读取JSON数据。例如:

.controller('youCtrl', function ($scope) {
    var firebase = {
      apiKey: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
      authDomain: "xxxxxxxxx.firebaseapp.com",
      databaseURL: "https://xxxxxx.firebaseio.com",
      storageBucket: "xxxxxx.appspot.com",
      messagingSenderId: "xxxxxxxxxx"
    };

    var ref = firebase.database().ref("users/ada");
    ref.once("value")
        .then(function (snapshot) {
          var key = snapshot.key; // "-Kc6xMyVGkwcGStYU5f4"
          $scope.output_data = snapshot.val(); // Data to your view
        });
 })

在您看来:

<ion-list>
  <ion-item ng-repeat="data in output_data">
    <p>{{data.FirstName}}</p>
    <p>{{data.LastName}}</p>
    <p>{{data.Comments}}</p>
  </ion-item>
</ion-list>

希望回答了你的问题。

相关问题