如何在Firebase中使用Angularjs forEach功能?

时间:2016-05-11 18:30:43

标签: javascript angularjs firebase

我有数据存储在Firebase中,如果满足几个条件,我试图检索,如果没有,则加载图像。我试过下面的代码但是在执行时忽略if语句并且总是加载图像。

`var refMyData = new Firebase("https://xxxxxx.firebaseio.com/meetings");

refMyData.once("value", function(snapshot) {
      snapshot.forEach(function(childSnapshot) {
        var childData = childSnapshot.val();

        if(childData.date == "11/5/2016") {
                $scope.meetingDate = childData.meetingDate;
                $scope.startTime = childData.startTime;
                $scope.endTime = childData.endTime;

                return true;

            } else if (childData.specialMSG == "6/8/2016") {
                $scope.specialMessage = "All meetings are canceled";            

                return true;

            } else {
                $scope.myLogoImg = 'img/logo.png';

                return true;
            };
      });
    });`

我在Firebase中有以下JSON数据,共有30个对象。

`[{
    "meetingDate": 11/5/2016",
    "startTime": "12:45",
    "endTime": "14:20"
}, {
    "meetingDate": "12/5/2016",
    "startTime": "12:40",
    "endTime": "13:00"
}, {
    "meetingDate": "13/5/2016",
    "startTime": "15:45",
    "endTime": "17:00"
}]`

0 个答案:

没有答案