有几个虫子。首先,你在使用
onChange
,但你的扣环组件需要
onDOMChange
代替道具。你要传递给的回调
一旦改变
也是错的,你想
onOverviewChange
从
patient
对象,而不是从
OverviewEditPane
的道具。最后,状态更新程序不正确。尝试以下修复:
class OverviewEditPane extends React.Component {
constructor(props) {
super(props);
}
render() {
const { overview, onchange } = this.props;
return (
overview.map(
(patient) =>
<TextInput
size='small'
key={patient.id}
id={patient.id}
name={patient.id}
value={patient.FName}
onDOMChange={onchange} />
)
)
}
}
class OverviewWrapper extends React.Component {
constructor(props) {
super(props);
}
render() {
return <OverviewEditPane {...this.props} />
}
}
class Patient extends React.Component {
state = {
PATIENT: [{
id: 6,
FName: "Chris",
LName: "Baker",
Height: "62",
Weight: 320,
DOB: "1988-09-18T00:00:00",
Active: true
}]
}
constructor(props) {
super(props);
this.onOverviewChange = this.onOverviewChange.bind(this);
}
onOverviewChange(event) {
const { target: { value, id } } = event;
this.setState(prevstate => ({
PATIENT: prevstate.PATIENT.map(p => {
if (p.id === parseInt(id, 10)) {
p.FName = value;
}
return p;
})
}));
}
render() {
return (
<OverviewWrapper onchange={this.onOverviewChange} overview={this.state.PATIENT} ovtype={this.state.COMPPROPS} />
)
}
}