gpt4 book ai didi

javascript - 不确定为什么数据没有按预期呈现

转载 作者:行者123 更新时间:2023-11-29 00:06:23 25 4
gpt4 key购买 nike

我正在尝试使用 src 文件夹中提供的本地 JSON 文件渲染一些数据,以下是我正在使用的源代码,还附有屏幕截图。我尝试执行console.log,它显示Chrome控制台区域中的项目为空,请告诉我以下代码可能出了问题的地方,非常感谢。

iOS Screenshot

    // import dependencies here
import React, { Component } from 'react';
import { View, StyleSheet, Text, Image, Dimensions, ImageBackground, TouchableOpacity, FlatList } from 'react-native';
import { Icon } from 'react-native-elements';

// import screens here

// import components here

import servicesData from '../components/servicesData.json';

const {height, width} = Dimensions.get('window');

export default class Services extends Component {
render() {
return (
<View style={styles.container}>
<FlatList
data={servicesData}
renderItem={(item) =>
<TouchableOpacity style={styles.button}>
<ImageBackground style={styles.backgroundImage} source={{ uri: item.image }} >
<View style={styles.overlay}>
<Text style={styles.title}>{item.title}</Text>
<Text style={styles.excerpt}>{item.excerpt}</Text>
<Icon name="arrow-right" type="font-awesome" size={30} color='#ffffff' />
</View>
</ImageBackground>
</TouchableOpacity>
}
/>
</View>
);
}
}

const styles = StyleSheet.create ({
container: {
flex: 1,
},
button: {
// flex: 0.5,
},
overlay: {
backgroundColor: 'rgba(0,0,0, 0.6)',
height: '100%'
},
backgroundImage: {
width: width,
justifyContent: 'center',
},
title: {
textAlign: 'center',
fontSize: 25,
paddingTop: 30,
color: '#ffffff',
fontFamily: 'Roboto-Bold',
},
excerpt: {
padding: 20,
paddingRight: 20,
fontSize: 18,
justifyContent: 'center',
color: '#ffffff',
fontFamily: 'Roboto-Regular',
},
})

最佳答案

谢谢大家的意见,但我发现了问题所在。提供的代码中缺少一组用于解构的花括号。以下是我的最后一段工作代码,可能对其他人也有帮助;

    export default class Services extends Component {
render() {
return (
<View style={styles.container}>
<FlatList
data={servicesData}
renderItem={({ item }) =>
<TouchableOpacity style={styles.button}>
<ImageBackground style={styles.backgroundImage} source={{ uri: item.image }} >
<View style={styles.overlay}>
<Text style={styles.title}>{item.title}</Text>
<Text style={styles.excerpt}>{item.excerpt}</Text>
<Icon name="arrow-right" type="font-awesome" size={30} color='#ffffff' />
</View>
</ImageBackground>
</TouchableOpacity>
}
/>
</View>
);
}
}

关于javascript - 不确定为什么数据没有按预期呈现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47950260/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com