【发布时间】:2019-01-24 08:00:22
【问题描述】:
我这样开始会话
state = {
firm: null,
office: null,
salesCode: null,
account: null
}
我的每个 TextField 都显示如下:
<TableCell>
<TextField
id="standard-bare"
defaultValue={items.data[i].firm}
margin="normal"
onChange={(e) => this.handleChange(e, items.data[i].id)}
/>
</TableCell>
然后我有一个handleChange事件
handleChange({ event, id }) {
const { data } = this.state;
data[id] = event.target.value;
this.setState({data})
}
当我运行并编辑 TextField 中的文本时,出现以下错误
TypeError: Cannot read property 'target' of undefined
UserDataTable.handleChange:75
72 |
73 | handleChange({ event, id }) {
74 | const { data } = this.state;
> 75 | data[id] = event.target.value;
| ^ 76 | this.setState({data})
77 | }
78 |
我正在尝试对表格实施编辑功能。因此,如果用户编辑文本,我会获得新的更新信息并执行 API 调用以相应地更新值。
【问题讨论】:
-
应该是
handleChange(event, id) { -
现在我得到 TypeError: Cannot set property '1' of undefined error
标签: reactjs material-ui