Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 将提取的数据获取到物料界面中的表格数据_Reactjs_Material Ui - Fatal编程技术网

Reactjs 将提取的数据获取到物料界面中的表格数据

Reactjs 将提取的数据获取到物料界面中的表格数据,reactjs,material-ui,Reactjs,Material Ui,我已经通过axios从url获取了一些数据。我想在React中将这些数据显示到材质ui表数据中。这里,“patient”是存储获取数据的数组。 代码: const[patient,setPatient]=React.useState([] 常量[状态,设置状态]=React.useState({ 栏目:[ {title:'Name',field:'Name'}, {标题:'性别',字段:'性别'}, {title:'Age',field:'Age',type:'numeric'}, {title

我已经通过axios从url获取了一些数据。我想在React中将这些数据显示到材质ui表数据中。这里,“patient”是存储获取数据的数组。 代码:

const[patient,setPatient]=React.useState([]
常量[状态,设置状态]=React.useState({
栏目:[
{title:'Name',field:'Name'},
{标题:'性别',字段:'性别'},
{title:'Age',field:'Age',type:'numeric'},
{title:'Birth Year',字段:'Birth Year',键入:'numeric'},
{标题:“电话号码”,字段:“电话号码”,键入:“tele”
},
],
数据:[
],
});
React.useffect(()=>{
axios.get()http://127.0.0.1:8000/patient/AppModel/')
。然后(res=>{
设置患者(恢复数据)
})
.catch(错误=>{
console.log(错误)
})
},[])
返回(
})}
但实际上我不知道如何将数组数据转换成对象数组

const [patient, setPatient] = React.useState([])
const [state, setState] = React.useState({
columns: [
  { title: 'Name', field: 'name' },
  { title: 'Gender', field: 'gender' },
  { title: 'Age', field: 'age', type : 'numeric' },
  { title: 'Birth Year', field: 'birthYear', type : 'numeric' },
  { title: 'Phone Number', field: 'phoneNumber', type : 'tele'  
  },
  ],
  data: [
  ],
 });

 React.useEffect(()=>{
 axios.get('http://127.0.0.1:8000/patient/AppModel/')
 .then(res =>{
  setPatient(res.data)
 })
.catch(err=>{
  console.log(err)
})
 },[])

return (
 <MaterialTable
  title="Patient List"
  columns={state.columns}
  data={state.data}
    />
 })}