创建类“ ScheduleList”并初始化数组元素
class ScheduleList extends Component {
state = {
schedulelistnew: []
};
用于使用axios从API填充数组元素
componentDidMount() {
axios.get(`https://apiv2.apifootball.com/?action=get_H2H&firstTeam=Chelsea&secondTeam=Arsenal&APIkey=******`)
.then(res => {
const schedulelistnew = res.data;
this.setState({ schedulelistnew });
});
}
将数组元素呈现给组件'ScheduleListItem'
render() {
return (
<div>
<Row>
<Col lg="9" md="8">
{this.state.schedulelistnew.map(item => (
<div className="strong textmb-3 pb-2" key={item.match_id}>
<ScheduleListItem item={item} />
</div>
))}
我想念什么?
答案 0 :(得分:-1)
当您忘记返回的地图过程
{this.state.schedulelistnew.map( item => {
return (
<div className="strong textmb-3 pb-2" key={item.match_id}>
<ScheduleListItem item={item} />
</div>
);
}
)}