我引用的示例如下:https : //codesandbox.io/s/github/tannerlinsley/react-table/tree/master/examples/sub-components
我想获取一个json文件并将后者的元素传递到表中,而不是像前面的示例那样生成它们。提取操作的说明对我很清楚,但我不明白如何将它们集成到“ makeData”文件中。
这是我的“ makeData”代码:
import ReactDOM from 'react-dom';
const range = len => {
const arr = []
for (let i = 0; i < len; i++) {
arr.push(i)
}
return arr
}
const newPerson = () => {
fetch('http://localhost:5000/api/azienda')
.then(res => res.json())
// .then((rows) => {
// ReactDOM.render(this.makeData(rows), document.getElementById('root'));
// });
}
export default function makeData(...lens) {
const makeDataLevel = (depth = 0) => {
const len = lens[depth]
return range(len).map(d => {
return {
...newPerson(),
subRows: lens[depth + 1] ? makeDataLevel(depth + 1) : undefined,
}
})
}
return makeDataLevel()
}
如有任何建议,我将感谢您
在构造函数中创建一个数组,将数据存储在该数组中,从服务器链接获取数据,然后将其放入表中
constructor(props, context) {
super(props, context);
this.state = { items: []};
}
getList = () => {
fetch("http://localhost:5000/api/azienda")
.then(res => res.json())
.then(items => this.setState({ items }))
.catch(err => console.log(err));
};
componentDidMount() {
this.getList();
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句