【问题标题】:I can't get information from a object inside object in React Native iOS我无法从 React Native iOS 中的对象内部的对象获取信息
【发布时间】:2017-02-14 06:15:25
【问题描述】:

我正在学习适用于 iOS 的 React Native

我的问题是我无法获取对象内部的信息,是图片的链接。

listView React Native 的内部 renderRow 代码

renderRow(rowData, sectionID, rowID) { 
 console.log(rowData.media.imagenes[0].imagenLink)

使用该代码,显示如下。

Picture of console.log(rowData.media)

如果我这样写代码,那应该可以工作

console.log(rowData.media.imagenes[0].imagenLink)

然后,它显示一个错误。

Error from Simulator

如果我在 renderRow() 之外编写代码,它可以工作。

console.log(this.state.datosJSON[0].media.imagenes[0].imagenLink)

然后我可以得到图片的链接。

我希望有人可以帮助我。

感谢您的宝贵时间

【问题讨论】:

  • 你能在listView中分享dataSource吗?
  • 当然,是constructor(props) { super(props); ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2}) this.state = { dataSource: ds.cloneWithRows(['row 1']), datosJSON:'' }; }
  • 我可以修复它,如果我使用 console.log 东西,它会给我错误,但如果我使用 {{ uri }} ,它可以工作,我不知道为什么

标签: javascript ios json listview react-native


【解决方案1】:

其实我不知道你是怎么做到的 .但是renderRow方法被使用如下。首先你应该定义dataSource进入状态。

getInitialState: function() {
    var ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2});
    return {
      dataSource: ds.cloneWithRows(['row 1', 'row 2']),
    };
  },

之后你应该使用ListViewrender方法。

  render: function() {
    return (
      <View>
        <ListView
          dataSource={this.state.dataSource}
          renderRow={this._renderRow}
        />
      </View>
    );
  },

完成这些之后,你可以插入代码renderRow方法。

renderRow(rowData, sectionID, rowID) { 
 console.log(rowData.media.imagenes[0].imagenLink);
}

我想如果你做了这些,代码就会正常工作。

【讨论】:

    猜你喜欢
    • 2021-08-09
    • 2012-05-18
    • 1970-01-01
    • 1970-01-01
    • 2022-07-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多