json - 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']
]
});
});
}
解决方案
推荐阅读
- android - 在 Android 中生成动态视图
- java - 如何使用 restfb 请求缩短超时时间?
- javascript - 使用鼠标从左到右和从右到左滚动
- javascript - 等待赛普拉斯 XHR 轮询中的特定响应
- java - 如果我需要初始化子类,如何使用抽象类?
- c# - 如何展平列表中的数据,然后使用 LINQ 计算每列中的内容?
- html - 此时元素符号上不允许使用属性宽度和高度
- reactjs - 最好在 redux react 中为每个状态添加错误
- c - 对字符串数组使用 strcpy() 或 strncpy()?
- node.js - 如何从 mongodb 聚合中的管道返回过滤数据?