如何使用React表库获取Json

如何使用React表库获取Json,json,reactjs,fetch,react-table,Json,Reactjs,Fetch,React Table,我提到的例子如下: 我希望获取一个json文件,并将后者的元素传递到表中,而不是像前面的示例中那样生成它们。 获取的说明对我来说很清楚,但我不明白如何将它们集成到“makeData”文件中 这是我的“makeData”代码: 从“react dom”导入ReactDOM; 常数范围=len=>{ 常数arr=[] for(设i=0;i{ 取('http://localhost:5000/api/azienda') .then(res=>res.json()) //。然后((行)=>{ //Re

我提到的例子如下:

我希望获取一个json文件,并将后者的元素传递到表中,而不是像前面的示例中那样生成它们。 获取的说明对我来说很清楚,但我不明白如何将它们集成到“makeData”文件中

这是我的“makeData”代码:

从“react dom”导入ReactDOM;
常数范围=len=>{
常数arr=[]
for(设i=0;i{
取('http://localhost:5000/api/azienda')
.then(res=>res.json())
//。然后((行)=>{
//ReactDOM.render(this.makeData(rows),document.getElementById('root');
//   });
}
导出默认函数makeData(…镜头){
const makeDataLevel=(深度=0)=>{
常数透镜=透镜[深度]
返回范围(len).map(d=>{
返回{
…newPerson(),
子镜头:镜头[深度+1]?makeDataLevel(深度+1):未定义,
}
})
}
返回makeDataLevel()
}

对于任何建议,我将感谢您

在构造函数中创建一个数组,在其中存储数据,从serverlink获取数据,然后将其放入表中

  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();
  }
  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();
  }