【发布时间】:2017-12-15 09:16:58
【问题描述】:
我的问题是,我应该使用哪些映射运算符将每个对象转换为数组?
首先,我从朋友节点检索用户密钥,如下图所示。
我想使用这些密钥从用户节点获取我的朋友列表。但是,结果会作为单独的对象返回,如下图所示。
因此,我无法迭代这些数据来显示视图。
我不确定这种方法是否正确。
这是我到目前为止所做的代码。
getMyFriendList() {
this.userService.getMyFriendKeys().switchMap(data => {
console.log('TEST', data);
return data;
}).subscribe(friend => {
this.userService.getFriends(friend.key).subscribe(res => {
console.log('TEST2', res);
// res is an objects
});
});
}
friends.json:
{
"5NnRVze6TVUeunLV0KXVmLby03J2": {
"VkwT5IgS7ZYqDZ4uz5Dh76inrAK2": true,
"dm8o0podI3gou0ob3wirkiyOGOu1": true
},
"VkwT5IgS7ZYqDZ4uz5Dh76inrAK2": {
"5NnRVze6TVUeunLV0KXVmLby03J2": true
},
"dm8o0podI3gou0ob3wirkiyOGOu1": {
"5NnRVze6TVUeunLV0KXVmLby03J2": true
}
}
Users.json:
{
"5NnRVze6TVUeunLV0KXVmLby03J2": {
"currentActiveStatus": "online",
"displayName": "Jeff Kim",
"email": "ziznzkak@gmail.com",
"photoURL": "https://firebasestorage.googleapis.com/v0/b/chattycherry-3636c.appspot.com/o/user-default.png?alt=media&token=f85be639-9a1c-4c79-a28d-361171358a41",
"statusMessage": "",
"uid": "5NnRVze6TVUeunLV0KXVmLby03J2",
"username": "helloworld"
},
"VkwT5IgS7ZYqDZ4uz5Dh76inrAK2": {
"currentActiveStatus": "offline",
"displayName": "John Doe",
"email": "hahehaheha@naver.com",
"photoURL": "https://firebasestorage.googleapis.com/v0/b/chattycherry-3636c.appspot.com/o/profilepics%2FVkwT5IgS7ZYqDZ4uz5Dh76inrAK2?alt=media&token=e9c2a8dc-5a10-42a7-a9c9-b28d53776f12",
"statusMessage": "programming is awesome!",
"uid": "VkwT5IgS7ZYqDZ4uz5Dh76inrAK2",
"username": "hello"
},
"dm8o0podI3gou0ob3wirkiyOGOu1": {
"currentActiveStatus": "offline",
"displayName": "Sia ",
"email": "ziznzkak4@daum.net",
"gender": "Female",
"photoURL": "https://firebasestorage.googleapis.com/v0/b/chattycherry-3636c.appspot.com/o/profilepics%2Fd65DhlrcCGaayOBaF2siVhauQbq1?alt=media&token=19e2b040-0fd9-4f59-9d56-406a817f58a3",
"statusMessage": "Hmm?",
"uid": "dm8o0podI3gou0ob3wirkiyOGOu1",
"username": "hellowo"
}
}
【问题讨论】:
-
能否正确提供
getMyFriendKeys()返回的body的json格式。和getFriends()返回的一个@
标签: javascript firebase rxjs