微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

在列表项中显示照片 undefined 不是对象

如何解决在列表项中显示照片 undefined 不是对象

我有一个产品列表,使用 react-native-elements 中的列表项显示。 我想将产品图片添加为产品名称左侧的“图标”。 我遇到困难

'undefined 不是对象'

当我调用图像时。 我不明白为什么会显示错误,我的数组如下所示:

Object {
    "cost": 1099.99,"created_at": "2018-05-17T20:58:31Z","custom_fields": Array [],"description": "","family_id": 5,"id": 5,"incl_tax": 1,"is_visible": 1,"name": "Apple MacBook Air 13.3'' LED 128 Go SSD 8 Go","photo": Object {
      "_1_": Object {
        "id": 1,"order": 1,"title_fr": "Apple-MacBook-Air-13-3-LED-128-Go-D-8-Go-RAM-Intel-Core-i5-bicoeur-a-1-8-Ghz-MQD32FN-Nouveau","url": "/i/p-4-6-5-146_5844_5_1.jpg",},"quantity": "0","reference": "","stock_status": "0","tax_rate_id": 1,"unit": "","updated_at": "2018-06-27T10:43:46Z","weight": 0,

所以我这样称呼我的照片:

1.url}} style={{ width: 25,height: 25}}/>

常量“URL”允许我将 url 的开头添加到我的数组 url 的末尾。 对我来说似乎是正确的,我不明白错误,你看到问题出在哪里了吗?我真的需要找出并解决这个问题。

感谢任何愿意花时间阅读我的帖子并帮助我的人。

这部分的代码

<ListItem
    style={{width:'100%'}}
    containerStyle= {{backgroundColor: item % 2 === 0 ? '#000' : '#ccc'}}
    bottomDivider
    onPress={() => this.props.navigation.navigate('ProductDetails',{productId:parseInt(item.id)})}>
    <ListItem.Content style={{flexDirection: 'row',justifyContent: 'space-between'}}>
      <Image source={{uri:URL+ item.photo._1_.url}}
             style={{ width: 25,height: 25}}/>
      <ListItem.Title style={{width: '65%',fontSize: 16}}>{ ( item.name.length > 20 ) ? item.name.substring(0,20) + ' ...'  :  item.name}</ListItem.Title>
      <ListItem.Subtitle style={{ color: '#F78400',position: "absolute",bottom: 0,right: 0 }}>{item.cost}€</ListItem.Subtitle>
    </ListItem.Content>
  </ListItem>

解决方法

看看这个

<Image source={URL+ item.photo["_1_"].url} style={{ width: 25,height: 25}}/>

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。