javascript - 为什么添加项目后我的数据没有从 Firebase 中显示
问题描述
我的卡片显示有问题。当我将产品添加到 firebase 时,它添加得很好,但是当我想显示它时,它什么也不显示。我认为问题来自关键,但我不知道如何解决问题。当我不添加产品而只显示数据库中已有的数据时,它显示得很好
export default class PostesMig extends React.Component {
constructor () {
super()
this.state = {
loading: true
}
}
componentDidMount() {
const ref = firebase.database().ref('PostesMig')
ref.on('value', snapshot => {
this.setState({
postes : snapshot.val(),
key : snapshot.key,
loading: false
})
})
}
goToTorchesAir = (item) => this.props.navigation.navigate('Torches', {torches: item.TorchesMigRefroidiesAir, previous:'PostesMig'})
goToTorchesEau = (item) => this.props.navigation.navigate('Torches', {torches: item.TorchesMigRefroidiesEau, previous:'PostesMig'})
render() {
if(this.state.loading) {
return (
<View style={styles.container}>
<Text>Chargement...</Text>
<ActivityIndicator size="large"></ActivityIndicator>
</View>
)
}
const list = this.state.postes
return (
<View style={styles.container}>
<ScrollView style={styles.scrollView}>
<FlatList
data={list}
keyExtractor={(item) => item.Id.toString()}
renderItem={({ item }) => (
<View>
<Card
title={item.DesignationAS400}
>
<Text style={{marginBottom: 10}}>
Code Commun : {item.CodeCommun}
</Text>
<Text style={{marginBottom: 10}}>
Réference Fournisseur : {item.RefFournisseur}
</Text>
<Button
onPress={this.goToTorches}pour onPress={()=>this.goToTorchesAir(item)}
buttonStyle={{borderRadius: 0, marginLeft: 0, marginRight: 0, marginBottom: 0}}
title='VOIR LES TORCHES AIR' />
{item.TorchesMigRefroidiesEau !== undefined &&
<Button
onPress={this.goToTorches}pour onPress={()=>this.goToTorchesEau(item)}
buttonStyle={{borderRadius: 0, marginLeft: 0, marginRight: 0, marginBottom: 0, marginTop: 4}}
title='VOIR LES TORCHES EAU' />
}
<Button
onPress={() => this.props.navigation.navigate("AddTorche", {torches: item})}
buttonStyle={{borderRadius: 0, marginLeft: 0, marginRight: 0, marginBottom: 0, marginTop: 4}}
title='AJOUTER UNE TORCHE' />
<Button
onPress={() => this.props.navigation.navigate("AddTorche", {torches: item})}
buttonStyle={{borderRadius: 0, marginLeft: 0, marginRight: 0, marginBottom: 0, marginTop: 4}}
title='MODIFIER LE POSTE' />
<Button
onPress={() => this.props.navigation.navigate("AddTorche", {torches: item})}
buttonStyle={{borderRadius: 0, marginLeft: 0, marginRight: 0, marginBottom: 0, marginTop: 4}}
title='SUPPRIMER LE POSTE' />
</Card>
</View>
)}
/>
</ScrollView>
<View>
<TouchableOpacity style={styles.button} onPress={() => this.props.navigation.navigate("AddPoste")}>
<Text>Ajouter un poste</Text>
</TouchableOpacity>
</View>
<TouchableOpacity style={styles.button} onPress={() => this.props.navigation.navigate("Home")}>
<Text>Retour</Text>
</TouchableOpacity>
</View>
)
}
}
解决方案
在你的FlatList
,你可以state
直接输入作为你的data
<FlatList
data={this.state.postes}
...
推荐阅读
- sql - 可序列化隔离级别的意外行为
- python - 如何使用pyspark从文件中查找分隔符
- javascript - Fusion Charts Zoomline React 错误:ChunkLoadError:加载块 6 失败
- command-line - 如何在命令行上处理 .fsproj 文件?
- python - 在 Flask 中将蓝图注册到应用程序中是什么意思?
- javascript - 如何添加属性或更改按钮的样式 onPress react native - native base
- reactjs - 提供者值上的 Typescript React UseReducer 类型错误
- python - 向 Django 频道消费者发送数据
- javascript - 编辑功能不保存对 React 中状态数据的更改
- python - Pandas 基于另一列的条件移位