0
我有一个TourEditor类,它是儿童和TourEditor类的父级,它在提交时处理表单。我希望父tourEditor在孩子中调用函数updateFiles(files)时更新组件对象,但不幸的是,它只保存孩子的初始状态并且不更新状态。关于如何解决这个问题的任何想法?当孩子/父母更改状态时更新父级
TourEditor.js
export default class TourEditor extends React.Component {
constructor(props){
super(props);
this.state = {"files": []};
this.updateFiles = this.updateFiles.bind(this);
}
componentDidMount() {
tourEditor({ component: this });
}
updateFiles(files) {
this.setState({
files: files
});
}
render() {
const { tour } = this.props;
return (<form
ref={ form => (this.tourEditorForm = form) }
onSubmit={ event => event.preventDefault() }
>
<FormGroup>
//....
</FormGroup>
</form>);
}
}
tourEditor.js
export default function tourEditor(options) {
console.log(options);
component = options.component;
validate();
}
我没有看到你打电话'updateFiles',你应该包括它太 – Khang