【发布时间】:2020-07-02 19:51:29
【问题描述】:
我使用firebase实时数据库,我可以提取照片数据 但是会在实时数据库中使用照片,它不会显示组件平面列表。
我的代码获取数据库:
componentDidMount() {
firebase.auth().onAuthStateChanged(user => {
if (user != null) {
const rootRef = firebase.database().ref();
const userRef = rootRef.child(`user/${user.uid}/car`);
this.setState({ uid: user.uid })
userRef.on('value', (childSnapshot) => {
const cars = [];
childSnapshot.forEach((doc) => {
cars.push({
distance: doc.val().distance,
time: doc.val().time,
price: doc.val().price,
photo:doc.val().photo,
key: doc.key,
});
this.setState({
cars: Object.values(cars)
})
});
})
}
});
}
扁平化
<FlatList data={this.state.cars}
renderItem={({ item }) => (
<List>
<ListItem avatar>
<Image style={{width:50,height:50}} source={item.photo}></Image>
</ListItem>
</List>)}
/>
不是秀照片"Picture"
【问题讨论】:
标签: node.js firebase react-native firebase-realtime-database