首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >图片的平面图是未定义的?

图片的平面图是未定义的?
EN

Stack Overflow用户
提问于 2019-12-10 10:55:12
回答 2查看 56关注 0票数 0

我试图在子组件中呈现图像的平面列表。图片数组是父状态组件的一部分,包含每个图片的uri。我是这样把它传给孩子的:

代码语言:javascript
运行
复制
<ImagePickerAndList
  pictures={this.state.pictures}
/>

然后是flatList in <ImagePickerAndList />

代码语言:javascript
运行
复制
<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>
     );
  }}
/>
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2019-12-10 11:02:45

不能在呈现项中更改变量名。如果您想在数组上迭代,那么对于每个元素,您必须使用item,而索引只是使用索引。

现在只需编辑您的代码,它就能工作了。

代码语言:javascript
运行
复制
<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>
     );
  }}
/>

项->从数组中获取元素

当前元素的索引->索引

我希望它有帮助,谢谢:)

票数 1
EN

Stack Overflow用户

发布于 2019-12-10 11:11:32

不能在呈现项中更改变量名。如果您想在数组上迭代,那么对于每个元素,您必须使用item,而索引只是使用索引。

现在只需编辑您的代码,它就能工作了。

代码语言:javascript
运行
复制
<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>
   );
  }}
/>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59265618

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档