【发布时间】:2019-09-22 13:39:55
【问题描述】:
我正在尝试创建从 API 获取的子类别列表并将它们显示在应用程序中。问题是我不知道如何将 Array (API) 中的项目转换为 List 项目。
componentDidMount(){
axios.get('/categories/' + this.props.match.params.id)
.then(response => {
console.log(response.data.children) //Array of strings
})
}
render(){
return(
<div className={classes.Showcategory}>
<h1>{this.props.match.params.id}</h1>
<li>Here I need for each string of the array a list item<li/>
</div>
);
}
【问题讨论】:
-
将响应存储在由状态管理的数组中,然后使用
Array.map返回它。
标签: javascript reactjs api axios