【问题标题】:Attendance Checking using firebase angular使用firebase angular进行考勤检查
【发布时间】:2016-09-10 08:52:44
【问题描述】:

我在使用 firebase 和 angular 进行 ionic 时遇到问题。我想要实现的是当用户单击日期列表然后例如 9 月 8 日然后用户可以看到 9 月 8 日的所有出席状态。

用户点击 9 月 8 日后。它显示了 9 月 8 日的用户数据列表和考勤状态。

这是我的 firebase 数据库

到目前为止,我可以显示每个日期和用户数据的列表。但问题是我的查询显示所有日期的状态(9 月 8 日和 9 日)。如何仅显示选定日期的状态?

这是我一直在处理的代码。

Controller.js

childUsers.orderByValue().on('value', function(snapshot){
    $timeout(function(){

        var snapshotVal = snapshot.val();

        $scope.users =snapshotVal;
        console.log($scope.users);

      });
    });

模板

 <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; ">

                    <div ng-if="item.status = 'true'">
                        <div class="ion-checkmark" style="display: flex;  vertical-align: middle;"></div>
                    </div>

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

知道如何解决这个问题吗?感谢任何帮助。

【问题讨论】:

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


    【解决方案1】:

    我找到了使用嵌套快照的解决方案,这是我的代码

    控制器

      var rootRef = new Firebase('https://example-app.firebaseio.com/');
        var childUsers = rootRef.child('users');
        var childDate = rootRef.child('tanggal');
        var rekapId = $stateParams.rekapId;
        console.log(rekapId);      
    
      childDate.child(rekapId).child('tanggalBaca').once('value',function(snap){
    
            $timeout(function() {
                 var snapshot= snap.val();
                $scope.tanggal = snapshot;       
                console.log($scope.tanggal);
                myAfterFunction();
             });
        })
    
        function myAfterFunction(){
    
       var dates = $scope.tanggal;
       console.log(dates);
       var rekapUsers = childUsers.on('value', function(snapshot){
            snapshot.forEach(function(childSnapshot){
                var key = childSnapshot.key();
                console.log(key);
                var childStatus = childUsers.child(key+'/status/'+dates);
                childStatus.on('value',function(grandsnap){
                    var snapval =grandsnap.val();
                    $scope.statusbaca = snapval;
                    $scope.key = key;
                    console.log($scope.statusbaca);
                    console.log($scope.key);
                  })
    
            })
            var snapshotVal = snapshot.val();          
            $scope.users =snapshotVal;
            console.log($scope.users);
        })     
    
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-15
      • 2019-01-29
      • 2022-06-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多