【问题标题】:React-Native FlatList White Screen doesn't load datasReact-Native FlatList White Screen 不加载数据
【发布时间】:2021-12-29 07:58:14
【问题描述】:

我想在 FlatList 中显示这些数据,但它只显示白屏:

const [datas,setDatas] = useState([
        {
            name:'dhinesh',
            phone:'9888888888',
            email:'asdasd@gmail.com',
            salary:'50000',
            position:'ww'
        },
        {
            name:'ramesh',
            phone:'93388888',
            email:'jhjj@gmail.com',
            salary:'90000',
            position:'sw'
        }
    ]);

这是我使用的代码:

            <FlatList
            data={datas}
            keyExtractor={(item, index) => index.toString()}
            renderItem={({item}) => {
                <View>
                    <Text>{item.name}</Text>
                    <Text>{item.phone}</Text>
                    <Text>{item.email}</Text>
                    <Text>{item.salary}</Text>
                    <Text>{item.position}</Text>
                </View>
            }}
            />

请给我一个解决方案

【问题讨论】:

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


    【解决方案1】:

    在您的视图中添加return

    renderItem={({item}) => {
        return (
            <View>
                <Text>{item.name}</Text>
                <Text>{item.phone}</Text>
                <Text>{item.email}</Text>
                <Text>{item.salary}</Text>
                <Text>{item.position}</Text>
             </View>
         )
     }}
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-11-28
      • 1970-01-01
      • 2021-08-22
      • 1970-01-01
      • 1970-01-01
      • 2020-05-23
      • 2018-04-14
      • 2021-03-23
      相关资源
      最近更新 更多