首页 > 解决方案 > react-native-table-component 将 Json 数据导入表

问题描述

我试图将 Json 文件中的一些信息导入到 react-native-table-component 的表中,我尝试将其导入到 ListView 并且有效,但我想要一个更好看的表来存储我的数据。首先,我的表在顶部有数据,数字 1-6,然后在 fetchWorkOrder() 函数中,我试图将行更改为 Json 文件中的数据。但无论我尝试什么,我总是在表中得到未定义的对象。

constructor(props){
super(props);
this.state = {
tableHead: [ 'Art', 'Prod', 'Hämtas', 'Lämnas', 'Mängd', 'Status'],
tableData: [
    ['1', '2', '3', '4', '5', '6'],
    ['1', '2', '3', '4', '5', '6']
]
}
}

componentDidMount(){
this.fetchWorkOrder();
//this.renderTable(); 
}

//https://gitlab.hiqkna.se/bth/bth-007-001/raw/master/workOrder.json
fetchWorkOrder(){
fetch("https://raw.githubusercontent.com/Digy95/Json-files/master/workOrder5.json")
.then((response) => response.json())
.then((response) => {
  this.setState({
    dataSource: response.workOrder1,
    tableData: [
        ['1', '2', `${response.workOrder1.articleNumber}`, '4', '5', '6'],
        ['1', '2', '3', '4', '5', '6']
    ]
  });
});
}

标签: jsonreact-nativereact-native-table-component

解决方案


推荐阅读