如何从firebase中检索对象?

时间:2016-09-14 02:41:22

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

我是角度和火力的新手。我有问题从firebase检索嵌套对象。这是我的代码。 的控制器

 var rootRef = new Firebase('https://ayobacaalkitab.firebaseio.com/');
    var childUsers = rootRef.child('users');
    var childDate = rootRef.child('tanggal');
    var rekapId = $stateParams.rekapId;

    console.log(rekapId);
    childDate.child(rekapId).child('tanggalBaca').on('value',function(snap){       
        $timeout(function() {
            var snapshot= snap.val();
            $scope.tanggal = snapshot;          
            myAfterFunction();
         });
    })
    function myAfterFunction(){
    console.log($scope.tanggal);   

   var dates = $scope.tanggal;
   console.log(dates);
   var rekapUsers = childUsers.on('value', function(snapshot){
        snapshot.forEach(function(childSnapshot){
           $scope.keyuser = childSnapshot.key();           
            stat();      
        })
        var snapshotVal = snapshot.val();      
        $scope.users =snapshotVal;
        console.log($scope.users);
    })
    function stat(){
        var keyusers =$scope.keyuser;
        var childStatus = childUsers.child(keyusers+'/status/'+dates);      
        $scope.statusbaca = $firebaseArray(childStatus); 
        console.log($scope.statusbaca);           
        console.log(keyusers);
        })
    }

    }

模板HTML

<div ng-repeat= "item in users">
            <div class="list card" style="padding:1%;">
                <div class="col-50" style="float:left;">

                <h5>{{item.displayName}} - {{item.handphone}}</h5>
                <h5>{{item.email}}</h5>  
                </div>
                  <div class="col-33" style="float:right; position: relative;" ng-repeat = "datas in statusbaca">

                    <h5>{{datas}}</h5>

                </div>
            </div>
        </div>

现在第一个问题是我可以使用{{datas}}在html中显示结果但是当我更改为{{datas.stat}}时它没有显示任何内容。我如何才能在html中显示统计数据。 第二个问题是html中的查询显示只显示firebase的最新对象。并不是firebae中的所有对象查询。我已经尝试将$ firebaseArray更改为$ firebaseObject。它仍然失败。

这是我的firebase的屏幕截图以及应用程序中的结果。

enter image description here enter image description here

正如您在结果中看到的,所有值结果都是false,但在firebase中,其中一个值为true的用户未显示。任何帮助表示赞赏。感谢

1 个答案:

答案 0 :(得分:0)

我认为这是你的风格问题,它在这里很有效,

     <body ng-app='myApp' ng-controller='MyController'>
   <div ng-repeat= "item in users">
            <div class="list card" style="padding:1%;">
                 <div ng-repeat="(key,value) in item.status">
                    {{item.displayName}}
                    <h5>{{key}}</h5>
                     <h5>{{value.stat}}</h5>
                 </div>
            </div>
   </div>
  </body>

WORKING DEMO