【问题标题】:Why I am not getting uuid id from firebase realtime database in react native app为什么我在本机应用程序中没有从 firebase 实时数据库获取 uuid id
【发布时间】:2023-01-13 23:38:49
【问题描述】:
我能够在 firebase 数据库中设置 UUID id 和消息,但是当我尝试从 firebase 获取 UUID 时,我无法获取该 UUID。如果您有任何想法,请帮助我,我是 firebase 的新手
const chatRoomRef = database().ref(firebaseMessages.CHAT_ROOM);
chatRoomRef.once('value').then(snapshot => {
console.log('User data: ', snapshot.val());
});
【问题讨论】:
标签:
reactjs
firebase
react-native
firebase-realtime-database
【解决方案1】:
据我了解,您正在尝试访问 children dataSnapshots 的 parent dataSnapshot 的密钥(UUID)。
如果这是你想要做的,那么试试这样:
const chatRoomRef = database().ref(firebaseMessages.CHAT_ROOM);
chatRoomRef.once('value').then(snapshot => {
//loop through the children here
snapshot.forEach((child) => {
//print the key or UUID of each child
console.log('User data: ', child.key);
});
});