【发布时间】:2021-06-28 14:36:15
【问题描述】:
我拿了一个数据表组件。在其中我想要每个对象一行。
return (
<Table striped bordered hover variant="dark">
<thead>
<tr>
<th>Nom</th>
<th>Adresse</th>
</tr>
</thead>
<tbody>
<tr>
<td>{this.props.obj.nom}</td>
<td>{this.props.obj.adresse}</td>
</tr>
</tbody>
</Table>
);
我的 obj 设置了这两个功能:
getEntreprise = () => {
axios.get('http://localhost:8080/api/ent')
.then(res => {
this.setState({ liste: res.data });
console.log(res.data);
console.log('Data récupérée1 !');
})
.catch(function (error) {
console.log(error);
})
}
dataTable() {
return this.state.liste.map((data,i) => {
return <DataTable obj={data} key={i}/>;
});
}
我不明白为什么它会为每个项目生成一个组件,而不是每个项目生成一个表格行
【问题讨论】: