사용자가 앞뒤로 이동할 수있는 양식이 많지만 서식이 돌아 왔을 때 양식은 왼쪽과 같이 있어야하며 모든 값은 즉시 제출하십시오.페이지를 reactjs로 남긴 후 양식에 값 저장
나는 모든 형태의 값을 일시적으로 저장하는 큰 객체를 유지할 것이라고 생각했으며, 그때까지 제출 된 것입니다. 페이지로 돌아올 때마다 그 특정 개체를 value 속성에 넣기 만하면됩니다.
이 문제는 채워진 양식으로 돌아 가면 더 이상 편집 할 수 없다는 것입니다.
어떻게해야합니까? 또한,이 작업을 수행하는 가장 좋은 방법이 있다면 완전히 변경할 수 있습니다.
// form3 only has to text fields, and form4 only has a file entry,
//which is why they aren't objects
//form1 and form2 on the other hand are huge and generate dynamically (I get
//all their fields through a get request and don't necessarily know
//how many there will be
export var formDataObject = {
form1:{},
form2:{},
form3:{
field1:"",
field2:""
},
form4:""
};
// for the next part I'll use form3 as an example since it is simple:
//The Form3 component is just a simple text input, I include the code
//of that too in case it's needed
export default class FullForm3 extends Component{
constructor(props){
super(props);
this.state ={
initial_field1: formDataObject.form3.field1,
initial_field2: formDataObject.form3.field2
}
}
render(){
var field1Value, field2Value;
if (this.state.initial_field1.length>0)
field1Value = formDataObject.form3.field1;
if (this.state.initial_field2.length>0)
field2Value = formDataObject.form3.field2;
return (
<div>
<Panel>
<Form3 controlId="field1Id" label={field1Label}
value={field1Value}/>
<br/><br/>
<Form3 controlId="field2Id" label={field2Label}
value={field2Value}/>
</div>
);
}
}
class Form3 extends Component{
constructor(props){
super(props);
this.state = {
value: formDataObject.form3,
};
this.handleChange = this.handleChange.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);
}
handleChange(e) {
const value = Object.assign({}, this.state.value);
value[e.target.id] = e.target.value;
this.setState({ value });
formDataObject.form3= this.state.value;
}
handleSubmit(e){
//things for submit (not important)
}
render(){
return (
<Form inline onSubmit={this.handleSubmit}>
<ControlLabel>{this.props.label}</ControlLabel>
<FormControl
type='text' label='Text'
value={this.props.value} onChange={this.handleChange}
/>
</FormGroup>
</Form>
)
}
}
내가있는 거 문제는 당신이하고있는 것입니다 당신을 생각 React의 일부 항목 및 React (글로벌 오브젝트)의 일부 항목이 아닙니다. 구성 요소를 여러 파일로 분할하고 소품을 통해 데이터를 전달하십시오. 당신이 필요로하는 것은 모든 폼 (글로벌 객체와 유사)에 대한 상태를 유지하는 모든 폼의 상위 컴포넌트이며 폼에 전달하여 자신의 상태를 변경하는 onchange 핸들러를가집니다. https://facebook.github.io/react/docs/lifting-state-up.html –
@MatthewHerbst에서 자습서를 읽고 다시 작성하십시오. 완벽하게 일했습니다! 정말 고맙습니다! – theJuls