问题
I'm working with Angularjs and Firebase. Right now I'm new at firebase for this I'm struggling to find solutions for my issues.
Imagine I'm sorting users like this
users:{
facebook:123456789:{
blog: [{
// List of blogs
}],
following: [{
// List of users auth.ids
}]
},
facebook:123456780:{
blog: [{
// List of blogs
}],
following: [{
// List of users auth.ids
}]
}
}
And getting logged in user blog object and iterating and pushing it to the array like this
var blogRef = new Firebase(FirebaseUrl + "/users/" + authData.uid + "/blog");
var userBlog = $firebaseArray(blogRef);
var userBlogDatas = []
blogRef.limitToLast(10).on("child_added", function(snapshot) {
var snap = snapshot.val();
userBlogDatas.push(snap);
});
So far everything working fine.
But how can i get latest blogposts from feeds from following users. Right now I have some idea which represents getting user blog datas and pushing them into array. I'm not sure is it right way or not...
I also read https://github.com/firebase/firefeed/blob/master/www/js/firefeed.js code but I could not get any information for myself.
Any ideas will be really helpfull.
Thank you
回答1:
There's a couple of ways to do this if I am understanding the question correctly.
One way is that instead of storing the user_id, store the user id as a key and the blog id as the value like
users
facebook:123456789
blog
// List of blogs
following
user_id_0: blog_id_x
user_id_1: blog_id_y
Then you can add an observer to each blog in the following node. You can get the path from the key/value pair. In this case Facebook:123456789 is following:
/users/user_id_0/blog/blog_id_x
/users/user_id_1/blog/blog_id_y
Another option would be to create a child node within the following node that contains two values: the user_id and blog_id.
users
facebook:123456789
blog
// List of blogs
following
follow_id_0
userid: user_id_0
blog: blog_id_0
follow_id_1
userid: user_id_0
blog: blog_id_1
In this case, facebook:123456789 is following user_id_0's blog 0 and blog 1
Note: user_id_0 and user_id_1 are actually Facebook:abcdefg users id's
来源:https://stackoverflow.com/questions/33593378/firebase-newest-feed-for-following-users