为什么我不能在 Flatlist 中显示我的项目?

约翰·多伊

我目前正在尝试学习 React-Native atm,但在我的 FlatList 中显示我的项目时遇到了一些问题。

下面是我的代码

import React from 'react';
import { FlatList, ActivityIndicator, Text, View  } from 'react-native';

export default class FetchExample extends React.Component {
  constructor(props){
    super(props);
    this.state = {
      isLoading: true,
      dataSource: []
    }
}

  componentDidMount(){

    return fetch('https://api.coindesk.com/v1/bpi/currentprice.json')
           .then((res) => res.json())
           .then((resJson) => {
           console.log('Here are the stuff', resJson.bpi)
           this.setState({
              isLoading: false,
              dataSource: resJson.bpi,
             })
           })
// catch any potential errors here
    .catch((error) =>{
      console.log(error)
    })
  }

  render(){
if(this.state.isLoading){
  return(
    <View style={{flex: 1, padding: 20}}>
      <ActivityIndicator />
    </View>
  );
}
return(
  <View style={{flex: 0.5, padding: 20}}>
    <Text>{console.log(this.state.dataSource)}</Text>
    <Text>Here's some testing text</Text>
    <Text>{console.log("This is in this.state.dataSource", this.state.dataSource)}</Text>
    {/* <FlatList 
      data= {this.state.dataSource}
      renderItem = {({item}) => <Text>{console.log(item)}</Text>} 
      /> */}
  </View>
)
  }
}

每当我取消对 FlatList 的注释时,模拟器都会向我发出错误消息,提示“不变违规:试图获取超出范围索引 NaN 的框架”

我究竟做错了什么?Atm 我只是想看看项目中有什么并了解如何使用 Flatlist

chetan 谢谢

这里我是怎么做的

 <FlatList
          data={[this.state.dataSource]}
          renderItem={({ item }) => this._renderListItem(item)}
        />

这里是 _renderListItem()

 _renderListItem(item){
    console.log(item)
      return(
        <View>
          <View style={{flexDirection:'row',width:'100%',backgroundColor:'red'}}>
          <Text>{item.USD.code}</Text>
          <Text>{item.USD.symbol}</Text>
          <Text>{item.USD.description}</Text>
          </View>
        </View>
        )
    }

这是世博会的链接,点击这里你明白了,如果你有任何问题,请问我......

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

为什么我不能在wxPython中销毁我的StaticText?

来自分类Dev

为什么我的评估不能在 C 中正确显示?

来自分类Dev

为什么我不能在 Pycharm 上运行我的文件?

来自分类Dev

为什么我不能在异步方法中调试代码?

来自分类Dev

为什么我不能在熊猫函数中应用shift?

来自分类Dev

为什么我不能在Typescript中扩展“ any”?

来自分类Dev

为什么我不能在Python中更改类的属性

来自分类Dev

为什么我不能在Python中创建这样的对象?

来自分类Dev

为什么我不能在Integer类中覆盖self?

来自分类Dev

为什么我不能在NSKeyedArchiver中编码NSValue?

来自分类Dev

为什么我不能在RStudio中安装“预测”包?

来自分类Dev

为什么我不能在表中插入数据?

来自分类Dev

为什么我不能在界面中访问此字段?

来自分类Dev

为什么我不能在Yii中更新此模型?

来自分类Dev

为什么我不能在iOS中更改按钮标题

来自分类Dev

为什么我不能在xcode中设置属性的值?

来自分类Dev

为什么我的模型不能在serviceRepository laravel中工作?

来自分类Dev

为什么我不能在DB中写数据帧?

来自分类Dev

为什么我不能在C ++中映射结构?

来自分类Dev

为什么我不能在iframe中嵌入特定的网址?

来自分类Dev

为什么我不能在Vue中访问html canvas?

来自分类Dev

为什么我不能在回调中调用useRef?

来自分类Dev

为什么我的硒不能在python脚本中工作?

来自分类Dev

为什么我不能在Mirth中访问xml消息?

来自分类Dev

为什么我不能在React中更改输入值?

来自分类Dev

为什么我不能在componentDidMount中收到引用?(反应)

来自分类Dev

为什么我不能在netlify中运行此脚本?

来自分类Dev

为什么我不能在声明中定义静态字段?

来自分类Dev

为什么我不能在/ sys中创建目录

Related 相关文章

  1. 1

    为什么我不能在wxPython中销毁我的StaticText?

  2. 2

    为什么我的评估不能在 C 中正确显示?

  3. 3

    为什么我不能在 Pycharm 上运行我的文件?

  4. 4

    为什么我不能在异步方法中调试代码?

  5. 5

    为什么我不能在熊猫函数中应用shift?

  6. 6

    为什么我不能在Typescript中扩展“ any”?

  7. 7

    为什么我不能在Python中更改类的属性

  8. 8

    为什么我不能在Python中创建这样的对象?

  9. 9

    为什么我不能在Integer类中覆盖self?

  10. 10

    为什么我不能在NSKeyedArchiver中编码NSValue?

  11. 11

    为什么我不能在RStudio中安装“预测”包?

  12. 12

    为什么我不能在表中插入数据?

  13. 13

    为什么我不能在界面中访问此字段?

  14. 14

    为什么我不能在Yii中更新此模型?

  15. 15

    为什么我不能在iOS中更改按钮标题

  16. 16

    为什么我不能在xcode中设置属性的值?

  17. 17

    为什么我的模型不能在serviceRepository laravel中工作?

  18. 18

    为什么我不能在DB中写数据帧?

  19. 19

    为什么我不能在C ++中映射结构?

  20. 20

    为什么我不能在iframe中嵌入特定的网址?

  21. 21

    为什么我不能在Vue中访问html canvas?

  22. 22

    为什么我不能在回调中调用useRef?

  23. 23

    为什么我的硒不能在python脚本中工作?

  24. 24

    为什么我不能在Mirth中访问xml消息?

  25. 25

    为什么我不能在React中更改输入值?

  26. 26

    为什么我不能在componentDidMount中收到引用?(反应)

  27. 27

    为什么我不能在netlify中运行此脚本?

  28. 28

    为什么我不能在声明中定义静态字段?

  29. 29

    为什么我不能在/ sys中创建目录

热门标签

归档