我在列表中有一个表格。 该列表将道具上带有主题数组的对象(另一个对象)传递给子窗体,并且当我更改状态值时,道具值也随之更改。 我想维护道具,以防用户取消更改。
constructor(props: IMinuteProps) {
super(props);
this.state = {
meeting: this.props.meeting,
EditingThemeDeliberation: undefined
};
}
更改现场事件后: (EditingThemeDeliberation是正在更改的主题)
private UpdateDeliberation(event) {
let { Reunion, EditingThemeDeliberation} = this.state;
EditingThemeDeliberation.Deliberation = event.target.value;
Reunion.Themes.splice(Reunion.Themes.findIndex(i => i.Id ===
this.state.EditingThemeDeliberation.Id), 1,EditingThemeDeliberation);
// Previous command changes both props and state
this.setState({ EditingThemeDeliberation: undefined, Reunion: Reunion
});
}