我有一个包含不同艺术家的对象数组。根据每个对象中是否有图像,我想显示不同的内容。
我尝试在我的渲染方法中使用 if/else
语句,但这当然不起作用。请参见下面的代码。
render: function() {
var cardList = this.props.artists.map(function(artist, index){
return(
<li key={index} className='card'>
<span>
{if artist.image}
<img src="{artist.image}">
{else}
<p>{artist.message}</p>
<p>LIKES <i className="fa fa-heart" aria-hidden="true"></i> {artist.likeCount }</p>
</span>
</li>
)
})
return (
<div className='tickerwrapper'>
<ul className='list'>{cardList}</ul>
</div>
)
}
myVal === true
可以简写为myVal
。 - TimoStaudinger