【发布时间】:2022-12-20 00:34:25
【问题描述】:
我一直在尝试将数据从我的 Firestore 数据库输出到 React native 中的 Flatlist,但到目前为止没有成功。
我使用这个 Flatlist for RN 和 Firestore docs 作为入门参考,但出于某种原因,我在这里遗漏了一些关于平面列表输出方法的内容,因为它不会输出平面列表本身。当我控制台记录位置数组时,它向我显示了我查询过的所有文档,因此它确实将它们全部推送到一个数组中,我的理解是 FlatLists 它们需要一个数组才能运行,但它不会抛出任何错误,只是不会'渲染。欢迎任何帮助!
useEffect(async () => {
const locations = [];
const querySnapshot = await getDocs(collection(db, "Location"));
querySnapshot.forEach((doc) => {
// doc.data() is never undefined for query doc snapshots
locations.push(doc.data());
console.log(locations);
});
return () => querySnapshot();
}, []);
return (
<View style={styles.screen}>
<Text>hello</Text>
<FlatList data={locations}
renderItem={({ item }) => (
<View >
<Text>name: {item.name}</Text>
<Text>Depth: {item.depth}m</Text>
<Text>GeoLocation: {item.geo}</Text>
<Text>id: {item.uid}</Text>
</View>
)}
/>
【问题讨论】:
标签: arrays firebase react-native google-cloud-firestore