【问题标题】:firebaseArray returning length of 0firebaseArray 返回长度为 0
【发布时间】:2016-06-09 19:06:16
【问题描述】:

我正在尝试使用以下代码从 firebase 中查找数组的长度:

(function() {
    'use strict';

    angular
        .module('com.td.oca.tDUITestHomepage')
        .controller('HomepageController', ['$scope', '$firebaseArray', function($scope, $firebaseArray) {
            $scope.greeting = 'Hola!';
            $scope.vm = this;

            $scope.fireData = new Firebase('https://mdm-ui-test-data.firebaseio.com/');

            $scope.vm.addData = addData;
            function Data() {
                name:'';
                address:'';
                postalCode:'';
            }

            $scope.vm.newData = new Data();
            $scope.vm.dataList = $firebaseArray($scope.fireData);
            $scope.testingLength = $scope.vm.dataList.length;
            $scope.testing = $scope.vm.dataList;

        }]);

})();

但是,scope.testing 返回:[{"name":"person A","phone":"11111111111","postalCode":"L1T3Y2"},{"name":"person B","phone ":"222222222222","postalCode":"L24YTW"},{"name":"person C","phone":"33333333333","postalCode":"au43rt"}]

我相信 $scope.testingLength 应该返回 3 的长度,但是,它返回的长度是 0。谁能解释为什么会这样?

【问题讨论】:

    标签: angularjs firebase-realtime-database


    【解决方案1】:

    按照这篇文章的建议:How to loop through $firebaseArray

    我能够解决问题

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-21
      • 2017-07-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多