0

I have some data

{
    "projects" : [
        {
            "projectName" : "Test Project 1",
            "dueDate" : "20/05/2014",
            "owner" : "Test owners 1",
            "categories" : [
                "JavaScript",
                "HTML",
                "CSS"
            ],
            "open" : true,
            "tasks" : [
                {
                    "taskName" : "Test task 1",
                    "targetDate" : "02/04/2014",
                    "categories" : [
                        "JavaScript",
                        "HTML",
                        "CSS"
                    ],
                    "open" : true
                },
                {
                    "taskName" : "Test task 2",
                    "targetDate" : "10/04/2014",
                    "categories" : [
                        "JavaScript",
                        "HTML"
                    ],
                    "open" : true
                }
            ]
        },
        {
            "projectName" : "Test Project 2",
            "dueDate" : "12/07/2014",
            "owner" : "Test owners 2",
            "categories" : [
                "JavaScript",
                "HTML",
                "CSS"
            ],
            "open" : true,
            "tasks" : [
                {
                    "taskName" : "Test task 1",
                    "targetDate" : "13/05/2014",
                    "categories" : [
                        "HTML",
                        "CSS"
                    ],
                    "open" : true
                },
                {
                    "taskName" : "Test task 2",
                    "targetDate" : "03/06/2014",
                    "categories" : [
                        "JavaScript"
                    ],
                    "open" : true
                }
            ]
        }
    ]
}

then I have a simple controller that is trying to output the object contained in each array index

TM.factories.getData = function(){
    var getProjects = new Firebase("https://<my-firebase>.firebaseio.com/projects");
    return getProjects;
};

TM.controllers = {};

TM.controllers.overviewCtrl = function($scope,$firebase){
    var taskArr = [];
    $scope.projectList =  $firebase(TM.factories.getData());
    $scope.projectList.$on("loaded", function() {
        $scope.projectList.$getIndex().forEach(function(key,i) {
            console.log($scope.projectList[key]);
        });
    });
};

Don't worry about how it's laid out I'm experimenting with writing it in different ways and it's very early dev work.

The question is why am I getting undefined when using "key" or "i"? if I console log just "key" or "i" I get 0,1.

0

1 Answer 1

1

Could you try this:

TM.controllers.overviewCtrl = function($scope,$firebase){
    var taskArr = [];
    $scope.projectList =  $firebase(TM.factories.getData());
    $scope.projectList.$on("loaded", function(projectList) {
        projectList.$getIndex().forEach(function(value,key) {
            console.log(projectList[key]);
        });
    });
};
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.