我的数组tabList
没有映射到我需要的<li>
标记。
我做错什么了。
import React, { Component } from 'react'
// import NeilProfile from './neil-profile.jpg'
import Expertise from './expertise'
import Work from './work'
import Activity from './activity'
export class Bottom extends Component {
constructor (props) {
super(props)
this.state = { currentTab: 1 }
this.changeTab = this.changeTab.bind(this)
}
changeTab (id) {
this.setState({ currentTab: id })
}
render () {
const tabList = [
{ 'id': 1, 'name': 'Work' },
{ 'id': 2, 'name': 'Expertise' },
{ 'id': 3, 'name': 'Activity'}
]
return (
<div className='profile-bottom'>
<header>
<ul className='profile-bottom__tab-navigation'>
{tabList.map(function(tab) {
<li key={tab.id} className={(this.state.currentTab === tab.id) ? 'active' : null}>
<a onClick={() => this.changeTab(tab.id)} >
{tab.name}
</a>
</li>
}.bind(this))}
</ul>
<div className='profile-bottom__filter'>
<p>Show only: <span>Articles</span></p>
</div>
</header>
<div className='profile-bottom__content'>
{this.state.currentTab === 1 ?
<Work />
:null}
{this.state.currentTab === 2 ?
<Expertise />
:null}
{this.state.currentTab === 3 ?
<Activity />
:null}
</div>
</div>
)
}
}
export default Bottom
最佳答案
您缺少地图功能的回报。像这样更新地图功能-
return (<li key={tab.id} className={(this.state.currentTab === tab.id) ? 'active' : null}>
<a onClick={() => this.changeTab(tab.id)} >
{tab.name}
</a>
</li>)
关于javascript - array.map在reactjs中不起作用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/41735039/