我的firebase数据结构如下......
test-db
- users
- c6fadsfjdaflasdjflkadsjflasdjf
- books
- g6734fdfadfadsfadfadsfadfdasfdaf
- title: 'Hi'
- genre: 'There'
- r78asdf8asdfdsaf87fdafadsf85fd
- books
- y664uu66df6dfdaff3sfdadfafhlklkl
- title: 'Thanks'
- genre: 'For Help'
如何获取所有用户拥有的图书对象?就这样......
{
{
title: 'Hi',
genre: 'There'
},
{
title: 'Thanks',
genre: 'For Help'
}
}
我当前的动作创建者如下所示,但它返回一个在不同用户下具有单独对象的对象。我需要一个单独的对象,然后我可以使用lodash(转换为数组)迭代以在我的FlatList中显示
My Current Action Creator返回错误的结果......
export const fetchAllBooks = () => {
return dispatch => {
try {
firebase.database().ref(`/users`)
.on('value', snapshot => {
snapshot.forEach((childSnapshot) => {
var childData = childSnapshot.val()
console.log('ChildData', childData)
})
})
} catch (error) {
console.log('fetchAllBooks Error', error)
}
}
}
感谢帮助,谢谢