React

松露反應框 onChange 錯誤:無法讀取未定義的屬性“setState”

  • August 20, 2018

這些是失敗的函式:

錯誤:未擷取的類型錯誤:

無法讀取 createOrgSchoolAddress 處未定義的屬性“setState”(App.js:187)

當我粘貼地址時(呼叫了第三個函式)

createOrgShortNameChange(event){
   this.setState({createCredentialOrgShortName: event.target.value});
}
createOrgOfficialNameChange(event){
   this.setState({createCredentialOrgOfficialSchoolName: event.target.value});
}
createOrgSchoolAddress(event){
   this.setState({createCredentialOrgSchoolAddress: event.target.value});
}

GitHub 連結

<table>
<tbody>
   <tr><td>School Short Name</td><td><input type="text" maxLength="30" size="32" value={this.state.createCredentialOrgShortName} onChange={this.createOrgShortNameChange} /></td></tr>  
   <tr><td>School Official Name</td><td><input type="text" maxLength="70" size="72" value={this.state.createCredentialOrgOfficialSchoolName} onChange={this.createOrgOfficialNameChange} /></td></tr>  
   <tr><td>School Address</td><td><input type="text" maxLength="42"  size="50" value={this.state.createCredentialOrgSchoolAddress} onChange={this.createOrgSchoolAddress} /></td></tr>  
   </tbody>
</table>

我希望這很簡單,但目前被卡住了。

每:https ://stackoverflow.com/questions/32317154/react-uncaught-typeerror-cannot-read-property-setstate-of-undefined

它建議我在頂部添加綁定(這不起作用),但將它們放置在適當的位置效果很好。

<tr><td>School Short Name</td><td><input type="text" maxLength="30"  size="32" value={this.state.createCredentialOrgShortName} onChange={this.createOrgShortNameChange.bind(this)} /></td></tr>  
<tr><td>School Official Name</td><td><input type="text" maxLength="70"  size="72" value={this.state.createCredentialOrgOfficialSchoolName} onChange={this.createOrgOfficialNameChange.bind(this)} /></td></tr>  
<tr><td>School Address</td><td><input type="text" maxLength="42"  size="50" value={this.state.createCredentialOrgSchoolAddress} onChange={this.createOrgSchoolAddress.bind(this)} /></td></tr>  

引用自:https://ethereum.stackexchange.com/questions/56907