[英]React - can't access passed function
我有一个使用组件显示行的表单,以便表单页面具有n个组件页面。
<form onSubmit={this.onSubmit} loading={loading} >
<table className="ui celled table" border="1">
<thead>
<tr>
<th >Status</th>
<th >Date </th>
<th >ID</th>
<th >Plan</th>
</tr>
</thead>
<tbody>
{this.state.claims.map ( claim => <ClaimRow claim= { claim } updateClaims={this.updateClaims} /> ) }
</tbody>
<tfoot className="full-width">
<tr>
<th colspan="4">
<div className="ui small button">
<Button Primary>Approve Selected</Button>
</div>
<div className="ui right floated button" >
Next
<i class="right arrow icon"> </i>
</div>
<div className="ui right floated button" >
<i class="left arrow icon"></i>
Prev
</div>
</th>
</tr>
</tfoot>
</table>
</form>
该页面正确显示ClaimRow,并且每一行都有一个OnChange事件处理程序。 在onChange事件处理程序/行中,我想调用updateClaims来设置父组件中单个行的状态。 这样,如果有人单击“批准”,则父组件的状态将所有更改准备发送到数据库。
当我单击“ onChange”时,我的onChange处理程序中出现错误,该错误无法引用updateClaims。
“ TypeError:_this.updateClaims不是函数”
我的onChange处理程序
onChange = e => {
this.setState({status: e.target.value} );
this.updateClaims(this.state._id,this.state);
}
它应该是
this.props.updateClaims(this.state._id,this.state)
在脚本中
<ClaimRow claim= { claim } updateClaims={this.updateClaims} />
updateClaims
为道具,以通过ClaimRow
组件,并将其上可用props
中它。
要访问它,在类组件中,您需要在this.props
上调用它
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.