Reactjs 反应选择:当用户从下拉列表中选择“其他”选项时,如何显示空的重复表单?

Reactjs 反应选择:当用户从下拉列表中选择“其他”选项时,如何显示空的重复表单?,reactjs,redux,react-redux,redux-form,react-select,Reactjs,Redux,React Redux,Redux Form,React Select,我正在使用react select组件,目前正在从下拉选择框列表中选择其他选项时显示redux表单组件。我尝试了onChange方法,但不起作用 下面是我的SelectInput.js 请指导我如何触发onChange方法并在从react select框中选择其他选项时显示 需要注意的一点是:我可以将选择框中的值提交到表单,但希望在选择其他选项时实现文本字段的显示。请导游 谢谢, shash您需要同时导入Field和reduxForm以使其工作 import { reduxForm, Field

我正在使用react select组件,目前正在从下拉选择框列表中选择其他选项时显示redux表单组件。我尝试了onChange方法,但不起作用

下面是我的SelectInput.js

请指导我如何触发onChange方法并在从react select框中选择其他选项时显示

需要注意的一点是:我可以将选择框中的值提交到表单,但希望在选择其他选项时实现文本字段的显示。请导游

谢谢, shash

您需要同时导入Field和reduxForm以使其工作

import { reduxForm, Field } from 'redux-form';
然后,您需要将表单包装在带有options参数的reduxForm函数中

export default reduxForm({
  form: 'SampleSelect'  // a unique identifier for this form
})(SampleSelect)
只有这样,才能传递自定义字段。看这个

最后,确保在构造函数中设置初始状态

constructor(props) {
    super(props);
    this.handleChange = this.handleChange.bind(this);
    this.state = { selected: false };
}
export default reduxForm({
  form: 'SampleSelect'  // a unique identifier for this form
})(SampleSelect)
constructor(props) {
    super(props);
    this.handleChange = this.handleChange.bind(this);
    this.state = { selected: false };
}