React native 如何将图像作为道具传递给自定义组件?
我在搜索屏幕中有一个自定义组件和平面列表,我正在尝试将每个结果加载到自定义组件中。flatlist中的数据是一个对象数组,它是来自API的响应。当我将图像、名称和其他详细信息传递给自定义组件以显示在卡上时,只加载样式,而不加载任何数据 这是我的密码 Card.js:React native 如何将图像作为道具传递给自定义组件?,react-native,react-native-android,react-native-flatlist,React Native,React Native Android,React Native Flatlist,我在搜索屏幕中有一个自定义组件和平面列表,我正在尝试将每个结果加载到自定义组件中。flatlist中的数据是一个对象数组,它是来自API的响应。当我将图像、名称和其他详细信息传递给自定义组件以显示在卡上时,只加载样式,而不加载任何数据 这是我的密码 Card.js: const Card = (props) => { return ( <View style={styles.containerStyle}>
const Card = (props) => {
return (
<View style={styles.containerStyle}>
<View>
<Image
source = {{uri : props.source}}
style={{ borderRadius: 100, width: 80, height: 80, margin: 10 }}
/>
</View>
<View style={{ marginLeft: 15, margin: 10 }}>
<Text>{props.name}</Text>
{/* <Text>{props.cuisine}</Text>
<Text>{props.cost}</Text> */}
</View>
</View>
)
}
const卡=(道具)=>{
返回(
{props.name}
{/*{props.美食}
{props.cost}*/}
)
}
Main.js:
<FlatList
data={this.state.data}
keyExtractor={(x, i) => x + i}
renderItem={({ item }) =>
<Card
source = {item.thumb}
name = {item.name}
/>
}
/>
x+i}
renderItem={({item})=>
}
/>
一个更清晰的图像
尝试
console.log
item.thumb。它可能是一个相对URL,在web上有效,但不幸的是在RN上无效。为什么我不知道名称?那么,这两个属性是否都存在于您所在州的项目中?您能否共享您的this.state.data
。嘿,你们两位感谢我没有想到,我猜,是在另一个对象中获得了数据。