亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

使用map時,Reaction‘無法讀取未定義的屬性’

使用map時,Reaction‘無法讀取未定義的屬性’

我正在做一個很基本的應用程序,我經常會遇到“TypeError:無法讀取未定義的屬性‘onPlayerScoreChange’”即使我正確地綁定了我的函數(我認為)'onPlayerScoreChange'是Grandparent組件,當用戶單擊“+”或“-”按鈕以更改玩家的得分時執行。如果有人能解釋一下是怎么回事會很有幫助,因為我想我是在this.onPlayerScoreChange = this.onPlayerScoreChange.bind(this)在曾祖父的構造函數中。父組件:class App extends React.Component {constructor(props) {     super(props);     this.onPlayerScoreChange = this.onPlayerScoreChange.bind(this)     this.state = {         initialPlayers: props.initialPlayers,     };}onPlayerScoreChange(delta, index) {     this.setState((prevState, props) => {         return {initialPlayers: this.prevState.initialPlayers[index].score += delta}     })}render() {     return(         <div className = "scoreboard">             <Header title = {this.props.title}/>             <div className = "players">                 {this.state.initialPlayers.map(function(player, index) {                     return(                         <Player                          name = {player.name}                          score = {player.score}                          key = {player.id}                          index = {index}                         onScoreChange = {this.onPlayerScoreChange}                         />                     )                 })}             </div>         </div>     )}}(組件具有默認標題支持)兒童部分:class Player extends React.Component {render() {     return(         <div className = "player">             <div className = "player-name">                 {this.props.name}             </div>             <div className = "player-score">                 <Counter score = {this.props.score} onChange = {this.props.onScoreChange} index = {this.props.index}/>             </div>         </div>)}}
查看完整描述

2 回答

  • 2 回答
  • 0 關注
  • 1056 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號