我尝试将对象数组转换为列表。现在,我只想将对象的一个"type“属性转换为一个列表项,但它不起作用。
下面是我的代码:
constructor(props){
super(props);
this.travelRawdata = [{type:15}];
}
render(){
return(
<ul>
{this.travelRawdata.forEach(element => <li>{element.type}</li>)}
</ul>
);}
我没有得到任何输出。如果我使用console.log(element.type)
,它工作得很好,所以我认为我的HTML标签有问题?
发布于 2018-10-09 03:34:49
你试过这个吗?
this.travelRawdata.map((item)=> { return (<li>{item.type}</li> })
https://stackoverflow.com/questions/52708941
复制相似问题