0
나는 redux-form 안에 material-ui 드롭 다운 메뉴가 있는데 그 값을 초기화하려고합니다.초기 상태에서 재료의 상태 -ui 드롭 다운에서 redux-form
componentWillMount(){
this.props.actions.exercise.fetchInfo(this.props.params.exerciseId);
this.props.actions.exercise.fetchAllTypes();
};
이상적 I : 나는이 작업을 파견하여 내가 원하는 값 [exercise.exercise_type_id
및 exercise.exercise_type_name
] 및 사용할 수있는 옵션 [types
, 다른 사람의 사이에서 id
및 name
속성을 가진 객체의 배열]의 목록을 모두 얻고있다 우리가 handleDropDownChange
로 변경을 처리하기 원하기 때문에,
_.map(this.props.types, (type) =>{
if (type.id == this.props.exercise.exercise_type_id){
this.setState({
dropDownValue: type.name
});
}
});
만에 초기 상태 : 같은 곳 뭔가를하고 싶습니다.
[물론 나는
state = {
dropDownValue: {this.props.exercise.exercise_type_name}
};
같은 감사하겠습니다 그러나 나는이 안티 패턴을 알고있다. 어쨌든 그것은 소품은 여전히 비어 있습니다 작동하지 않습니다]
내 드롭은 다음과 같습니다.
<DropDownMenu {...exercise_type_name} //does nothing
value={dropDownValue}
onChange={onDropDownChange}>
{_.map(types, (type) => {
return <MenuItem key={type.id} value={type.name} primaryText={type.name}/>;
})}
이
더 코드 :
//...
state = {
dropDownValue: ''
};
//...
handleDropDownChange = (event, index, value) => {
this.setState({
dropDownValue: value
});
};
//...
function mapStateToProps(state){
return {
exercise: getExerciseInfo(state),
initialValues: getExerciseInfo(state),
request: getExRequest(state),
types: getExTypes(state)
};
}
//....
export default reduxForm({
form: 'EditExerciseForm',
fields: ['exercise_type_name', 'max_errors_percentage', 'min_speed']
}, mapStateToProps, mapDispatchToProps)(ExerciseEdit);