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

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

React - 在動態表中調用 OnChange 會產生 Uncaught TypeError

React - 在動態表中調用 OnChange 會產生 Uncaught TypeError

慕哥9229398 2022-07-21 22:24:34
當創建表的嚴格要求及其行開始發揮作用時,我目前遇到了錯誤。請注意,我省略了代碼的不相關方面,問題被隔離到將 onChange 添加到表行的輸入時。我不確定為什么會出現這個問題,但我假設這可能與表是基于映射動態創建的事實有關,并且在創建表行時出現問題,我錯過了一些在這種情況下正確調用 onChange 的正確語法類型?class SkillTable extends React.Component<any,any>{  constructor(props: any) {    super(props);    this.state = {      skillList: [],      unTrainedList: [],      classSkill: [],      playerSkills: [],    };    this.handlePopulates = this.handlePopulates.bind(this);    this.handleSkillChange = this.handleSkillChange.bind(this);  }renderTableRows(skill, index)  {    return (      <tr key={index}>        <td>{skill.unTrainedTrue()}</td>        <td>{skill.classSkillTrue()}</td>        <td>{skill.skillName}</td>        <td>{skill.abilityName}</td>        <td>{skill.skillTotal}</td>        <td> <input type="number" value={skill.skillRank} onChange={this.handleSkillChange}/> </td>        <td> <input type="number" value={skill.abilityMod}/> </td>        <td> <input type="number" value={skill.raceMod}/> </td>        <td> <input type="number" value={skill.miscMod}/> </td>        <td> <input type="number" value={skill.synergyMod}/> </td>        <td> <input type="number" value={skill.skillCost}/> </td>      </tr>    )  }  render() {    return (      <div>        <table className="table table-bordered">          <thead>            <tr>              <th>UT</th>              <th>CS</th>              <th>Skill Name</th>              <th>Ability</th>              <th>Skill Total</th>              <th>Rank</th>              <th>Ability Mod</th>              <th>Race Mod</th>              <th>Misc Mod</th>              <th>Synergy Mod</th>              <th>Skill Cost</th>            </tr>          </thead>          <tbody>            {this.state.playerSkills.map(this.renderTableRows)}          </tbody>        </table>        </div>    );  }}  handleSkillChange(evt)  {    //LOGIC HERE, BUT CRASH ON CALL  }
查看完整描述

1 回答

?
素胚勾勒不出你

TA貢獻1827條經驗 獲得超9個贊

我認為您也應該將 renderTableRows 綁定到您的組件。例子:


constructor(props: any) {

  super(props);


  this.state = {

    skillList: [],

    unTrainedList: [],

    classSkill: [],

    playerSkills: [],

  };

  this.handlePopulates = this.handlePopulates.bind(this);

  this.handleSkillChange = this.handleSkillChange.bind(this);

  this.renderTableRows = this.renderTableRows.bind(this);

}


查看完整回答
反對 回復 2022-07-21
  • 1 回答
  • 0 關注
  • 135 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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