【问题标题】:RN JS TypeError: undefined is not an object (evaluating 'item.link.photo.photo_604')RN JS TypeError:未定义不是对象(评估'item.link.photo.photo_604')
【发布时间】:2018-07-08 13:28:54
【问题描述】:

我正在尝试获取数据,数据输出到控制台,但是错误发生的一切都很顺利...

JOSN 数组 vk newsfeed !

代码:

export function ParseAttach(content) {
  if (content == undefined) return true;
  let img = [];
  let index = 0;

  content.map(function (item, i) {
    if (item.type == 'photo' || item.type == 'graffiti') {
      index++;
      img[0] = index;
      img[index] = item.photo.photo_604;
    } else if (item.type == 'link') {
      index++;
      img[0] = index;
      console.log(item.link.photo.photo_604);
      img[index] = item.link.photo.photo_604;
    }
  });
}

enter image description here enter image description here

【问题讨论】:

  • 向我们展示item.photo.photo_604 对象的外观。
  • 解决问题如下我创建新函数
  • 抱歉,您的评论几乎无法阅读。
  • 对不起,我的英语水平谷歌翻译
  • 对不起,我明白了这个问题。我的意思是您在评论中的答案格式不可读。

标签: javascript reactjs react-native


【解决方案1】:

您不需要额外的功能。

你可以这样做:

export function ParseAttach(content) {
  if (content == undefined) return true;
  let img = [];
  let index = 0;

  content.map(function (item, i) {
    if (item.type == 'photo' || item.type == 'graffiti') {
      index++;
      img[0] = index;
      img[index] = item.photo.photo_604;
    } else if (item.type == 'link') {
      index++;
      img[0] = index;
      img[index] = item.link.photo && item.link.photo.photo_604;
    }
  });
}

【讨论】:

    猜你喜欢
    • 2021-12-17
    • 2021-12-01
    • 2019-11-16
    • 2020-02-09
    • 2019-12-07
    • 2022-01-01
    • 2019-01-20
    • 2014-06-13
    • 2021-07-24
    相关资源
    最近更新 更多