【发布时间】:2018-10-02 01:19:50
【问题描述】:
我已将我的 redux 存储映射到道具,但我现在无法动态渲染它。我也尝试过projectCards(){...} 语法,但那完全是在黑暗中拍摄。我的控制台日志显示了我想要的对象。我也尝试使用projects.map,但我不认为我想将返回值放入一个新数组中。我只想要页面上更多的<Card/> 项目,动态呈现。我哪里做错了?任何帮助,将不胜感激。
Class Projects extends...
.
.
.
projectCards = () => {
if ( this.props.projects.length !== 0 ) {
this.props.projects.forEach((project) => {
return <Card fluid color='green' header={project.name} />
})
}
}
render(){
return(
<Container>
<br/>
<Card.Group>
<Card fluid color='green' header='Option 1' />
<Card fluid color='blue' header='Option 2' />
<Card fluid color='red' header='Option 3' />
{ this.projectCards() }
</Card.Group>
</Container>
)
}
}
【问题讨论】:
-
使用
.map()而不是.forEach()。一些过去有用的 StackOverflow 答案:stackoverflow.com/questions/47442462/…, stackoverflow.com/questions/42460357/…
标签: reactjs react-redux semantic-ui semantic-ui-react