简体   繁体   English

为什么我的数据在添加项目后没有从 firebase 显示

[英]why my data is not displayed from firebase as soon as I add an item

I have a problem with the display of my cards.我的卡片显示有问题。 when i add a product to firebase it adds well but when i want to display it it doesn't display anything.当我将产品添加到 firebase 时,它添加得很好,但是当我想显示它时,它什么也不显示。 I think the problem comes from the key but I don't know how to solve the problem.我认为问题来自关键,但我不知道如何解决问题。 when I do not add a product and I just display the data that I already have in the database it displays well当我不添加产品而只显示数据库中已有的数据时,它显示得很好

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>
        )
    }
}

在此处输入图像描述

In your FlatList , you can input the state directly as your data在您的FlatList中,您可以直接输入state作为您的data

<FlatList
  data={this.state.postes}
  ...

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 一旦我向我的数组添加一个项目,我就无法从我的数组中删除一个项目 - As soon as i add an item to my array i am unable to delete an item from my array 为什么我在其中输入内容后报价就消失了? - Why my quotation is disappearing as soon I type something inside it? 为什么在从Firebase加载数据之前需要运行两次此功能? - Why do I need to run this function twice before it loads my data in from firebase? 我正在使用 React 从 Firebase 检索数据,但我的渲染 function 中未定义 userItem 为什么 - I'm using React to retrieve data from Firebase, but the userItem is not defined in my render function why 无法显示React中的Axios获取方法响应,无法在我的博客应用程序中以数组的形式从Firebase获取数据 - Axios get method response in React cannot be displayed getting data from firebase as an array in my blog application 如何从我的 web 到 firebase 添加不带引号的数据 - How to add data without quotations from my web to firebase 我无法使用 firebase 从我的文档中获取我的数据 - I can't get my data from my document with firebase 为什么来自 Firebase 的数据没有在我的 FlatList (React Native) 中呈现? - Why is the data from Firebase not rendering in my FlatList (React Native)? innerHtml =不显示firebase数据 - firebase data are not displayed by innerHtml = 如何从我的 firebase 数据库中检索数据? - How can I retrieve data from my firebase database?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM