【问题标题】:Mistake to render data on FlatList(native) - React Native在 FlatList(native) 上呈现数据的错误 - React Native
【发布时间】:2020-06-05 18:17:21
【问题描述】:

我有一个 React Native 应用程序,它从 API 接收数据并呈现到 FlastList。 然而正在发生一个像图像一样的麻烦。

    <ScrollView>
 <FlatList
                data={MyAPIData}
                renderItem={({ item, index }) => (
                  <ContainerFlatList
                    style={{
                      backgroundColor: index % 2 === 0 ? '#F4F4F4' : '#ffff',
                    }}
                  >
                    <TextKey>
                      {item.data1}
                    </TextKey>
                    <TextFlatList>
</ ScrollView>

有人经历过这种情况吗?

【问题讨论】:

    标签: javascript reactjs react-native react-native-flatlist


    【解决方案1】:

    一些可能对您有所帮助的事情。

    1- 使用 ScrollView 需要将父容器包装到 {flex: 1}

    2- 在flatlist react-native's doc 之后,我们看到您需要将其包装在 SafeAreaView 中,而不是 ScrollView 中,这是我开发的 App 的示例:

                   <SafeAreaView style={styles.safeView}>
                        <FlatList
                            numColumns={2}
                            columnWrapperStyle={styles.list}
                            ItemSeparatorComponent={() => <Text></Text>}
                            data={this.state.arrEstab}
                            renderItem={({ item }) => <CardComponent style={styles.card} 
                            navigation= {this.props.navigation} nome={item.nome} imgUrl= 
                            {this.props.selectedType.url} estab={item} parent="porTipo"/>}
                            keyExtractor={item => item._id}
                        />    
                    </SafeAreaView>
    
                    ...,safeView: {
                        height: '80%',
                        width: '100%'
                    },...
    

    3- 为避免错误,如果您没有 ID,请提供 keyExtractor,只需传递项目的索引即可。

    【讨论】:

    • GM-atteoni 我之前尝试过这些解决方案,但没有正确的返回。
    • 嗯,我认为您遇到了 CSS 问题。可以展示一下ContainerFlatList组件的代码吗?
    猜你喜欢
    • 1970-01-01
    • 2019-05-22
    • 2019-03-17
    • 2021-03-25
    • 1970-01-01
    • 2019-10-18
    • 2019-06-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多