我试图在子组件中呈现图像的平面列表。图片数组是父状态组件的一部分,包含每个图片的uri。我是这样把它传给孩子的:
<ImagePickerAndList
pictures={this.state.pictures}
/>然后是flatList in <ImagePickerAndList />
<FlatList //what I see is nothing renders
data={props.pictures}
extraData={props.pictures}
horizontal
keyExtractor={picture => picture} //no idea if this is a good practice or not
renderItem={({ picture }) => {
console.log(picture); //this will log undefined for each item in list
console.log('hi'); //this will log for each item in list
return (
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
<Image source={{ uri: picture }} style={{ width: 100, height: 100 }} />
</View>
);
}}
/>发布于 2019-12-10 11:02:45
不能在呈现项中更改变量名。如果您想在数组上迭代,那么对于每个元素,您必须使用item,而索引只是使用索引。
现在只需编辑您的代码,它就能工作了。
<FlatList //what I see is nothing renders
data={props.pictures}
extraData={props.pictures}
horizontal
keyExtractor={picture => picture} //no idea if this is a good practice or not
renderItem={({ item,index }) => {
console.log(picture); //this will log undefined for each item in list
console.log('hi'); //this will log for each item in list
return (
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
<Image source={{ uri: item}} style={{ width: 100, height: 100 }} />
</View>
);
}}
/>项->从数组中获取元素
当前元素的索引->索引
我希望它有帮助,谢谢:)
发布于 2019-12-10 11:11:32
不能在呈现项中更改变量名。如果您想在数组上迭代,那么对于每个元素,您必须使用item,而索引只是使用索引。
现在只需编辑您的代码,它就能工作了。
<FlatList //what I see is nothing renders
data={props.pictures}
extraData={props.pictures}
horizontal
keyExtractor={picture => picture} //no idea if this is a good practice or not
renderItem={({ item,index }) => {
console.log(picture); //this will log undefined for each item in list
console.log('hi'); //this will log for each item in list
return (
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
<Image source={{ uri: item}} style={{ width: 100, height: 100 }} />
</View>
);
}}
/>https://stackoverflow.com/questions/59265618
复制相似问题