如何读取 (Firebase & FirebaseIndex) 对象?
我的 Ctrl 看起来像:
var url = 'https://MYFIREBASE.firebaseio.com/';
var toDoRef = new Firebase(url);
var index = 'podio_covers/'+ $routeParams.label_id +'/limesurveys/';
var master = 'podio_surveys';
var surveys = new FirebaseIndex(toDoRef.child(index), toDoRef.child(master))
$scope.surveys = angularFireCollection(surveys);
console.log ($scope.surveys) 看起来像:
[add: function, remove: function, update: function]
0: angularFireItem
$id: "855243"
$index: 0
$ref: J
current_revision: Object
fields: Object
initial_revision: Object
item_id: 51176724
last_event_on: "2013-06-09 18:56:25"
limesurvey_data: Object
ratings: Object
rights: Array[10]
title: "855243"
__proto__: angularFireItem
add: function (item, cb) {
length: 1
remove: function (itemOrId) {
update: function (itemOrId) {
__proto__: Array[0]
现在 - 我必须遍历所有结果。$scope.surveys.length => 不起作用。
阅读 $scope.surveys.0.title =>错误!我看到了 - [add: function, remove: function, update: function] - 有没有办法阅读 $scope.surveys.0.title ?
编辑1: @Kato(希望更清楚)
在这里你可以看到我当前的 Ctrl 尝试:
var url = 'https://XXXXX.firebaseio.com/';
var toDoRef = new Firebase(url);
var index = 'podio_covers/'+ $routeParams.label_id +'/limesurveys/';
var master = 'podio_surveys';
var surveys = new FirebaseIndex(toDoRef.child(index), toDoRef.child(master))
$scope.surveys = angularFireCollection(surveys);
console.log ('surveys[0]');
console.log ($scope.surveys[0]); **=> Undefined**
console.log ('childRefs');
console.log (surveys.childRefs);
var count = $scope.surveys.length;
console.log (count); **=> Undefined**
//--------------------------------------------------------------
// LOOP trough all surveys.
//--------------------------------------------------------------
for (var i = 0; i < count; i++) {
console.log ($scope.surveys[i]);
// do something with $scope.surveys[i]
}
编辑2:
$timeout(function() {
// Waiting until Data is loaded.
count = $scope.surveys.length;
console.log (count);
//Do Loop here
}, 1500;