請查看我的代碼。使用geofire和firebase循環訪問數組時重複數據
var posts = PostsData.getPosts();
var postFunc = function(key) {
return posts[key];
}
$scope.$watch($scope.active, function() {
$timeout(function() {
var markers = [];
for (var key in posts) {
console.log(key);
var p = gf.get(key).then(function(location) {
var post = postFunc(key);
console.log(key);
return ({
idKey: key,
title: post.title,
coords: {
latitude: location[0],
longitude: location[1]
}
});
});
markers.push(p);
}
$q.all(markers).then(function(markers) {
$scope.markers = markers;
});
});
})
}
在循環內有兩行 「的console.log(密鑰)」。 第一個console.log輸出唯一鍵的數據的準確表示。第二個console.log打印重複相同的數據,這是不準確的。我無法理解爲什麼會發生這種情況。
非常感謝您的幫助。
非常感謝!我不得不做一些小的改變,但它的工作。 –