【发布时间】:2016-05-23 10:28:00
【问题描述】:
我正在尝试从 Ionic 中的所有用户那里检索帖子(没有特定的用户 ID)。我可以从数据库中的第一个用户那里获取所有帖子,但是在从其他用户那里获取帖子时遇到了麻烦。
这是我的 firebase 结构的简化版本:
"posts_meta" : {
"uid" : {
"post-id" : {
"title": "",
"content": ""
},
},
"uid" : {
"post-id" : {
"title": "",
"content": ""
},
"post-id" : {
"title": "",
"content": ""
},
}
在这里,我尝试先遍历用户,然后使用嵌套的 foreach 遍历每个用户的帖子:
.factory('Timeline', function($q, Profile, Utils, Codes) {
var self = this;
self.getAllPosts = function() {
var qGet = $q.defer();
var ref = new Firebase(FBURL);
ref.child("posts_meta").once("value", function(snapshot) {
snapshot.forEach(function(childSnapshot) {
childSnapshot.forEach(function(grandchildSnapshot) {
qGet.resolve(grandchildSnapshot.val());
})
})
}, function (error) {
Codes.handleError(error);
qGet.reject(error);
});
return qGet.promise;
};
我做错了什么?我错过了什么吗?
【问题讨论】:
标签: angularjs ionic-framework firebase firebase-realtime-database