您尚未绑定要使用的map函数onscoreChange = {this.onPlayerscoreChange}
,
您可以使用绑定或箭头功能进行绑定
需要PS绑定,因为map函数的上下文不同于React Component上下文,因此this
该函数内部不会引用React Componentsthis
,因此您无法访问React Component类的该属性。
{this.state.initialPlayers.map((player, index)=> {
return(
<Player
name = {player.name}
score = {player.score}
key = {player.id}
index = {index}
onscoreChange = {this.onPlayerscoreChange}
/>
)
})}
{this.state.initialPlayers.map(function(player, index) {
return(
<Player
name = {player.name}
score = {player.score}
key = {player.id}
index = {index}
onscoreChange = {this.onPlayerscoreChange}
/>
)
}.bind(this))}