首页 > 解决方案 > 从 React Native 表中获取 API 数据

问题描述

我正在尝试在 React Native 表中显示我的 api 数据,但我的行数据总是为空

<View style={{marginTop:200}}> 
  {data.map((item,key)=>(

        <Table key=. 
{key}borderStyle={{borderWidth: 
 2, 
borderColorr: '#c8e1ff'}} style=. 
{{height:'100%'}} >
<Row data={this.state.tableHead} 
stylee={styles.head} textStyle=. 
{styles.text} widthArr=. 
{[46,50,65,65,40,80,150]}/>
<Rows data=
{item.Designation.displayName}
  >
   
    </Rows>
   </Table>

这是我从 api 获取的数据,更具体地说,我的数据库中有一个名为 article 的表包含名称指定

componentDidMount(){
const 


  apiUrl=
  'http://128.168.1.10:8080/api/ 
  articles'';
  fetch(apiUrl,{
  method:'get',
  headers:{
    'Accept':'application/json',
    'Content- 
     Type'':'application/json'
     }
 
     })
     .then((response) => 
     response.json())
     .then((responseJson) => {
      this.setState({
      data:responseJson
      
      })
    }
  
  
     )
     .catch((error) =>{
      console.log(error)
     })

     }

标签: node.jsreactjsdictionarydatatablefetch-api

解决方案


推荐阅读