【发布时间】:2018-11-27 09:16:52
【问题描述】:
我有一个表单,我使用一个组件来显示行,以便表单页面有 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);
}
【问题讨论】:
标签: javascript reactjs react-native