请查看我的代码。使用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打印重复相同的数据,这是不准确的。我无法理解为什么会发生这种情况。
非常感谢您的帮助。
非常感谢!我不得不做一些小的改变,但它的工作。 –