React-select选项未被选中

时间:2017-12-29 06:43:05

标签: javascript reactjs redux react-select

我正在使用react-select包。当我选择一个下拉选项时,我的onChange操作正常工作并更新状态。但该选项未被选中。意思是,它不显示映射到状态的值,而只显示默认占位符。

我想我缺少一些小东西,但我有些新的反应和redux,我不知道这可能是什么。感谢您的帮助:)

Body.js

<Select id="input-field" value={this.props.create.selectedOption} onChange={this.props.addOption}
   options={[
      { value: 'navigate', label: 'Navigate to <URL>' },
      { value: 'enter', label: 'I enter <InputValue> to the <ElementKey>' },
      { value: 'click', label: 'Click on <ElementKey>' },
      ]}
/>


const mapStateToProps = (state, ownProps) => {
    return {
        create: state.reducerCreate
    }
}

Reducer.js

const initialState = {
    feature: '',
    scenarios: [],
    activeIndex: '',
    selectedOption: ''
}

1 个答案:

答案 0 :(得分:0)

回答我自己的问题,我发现只是传递选定的选项标签/值是不够的,我们需要传递整个对象;

len5<-data.frame("C1"=character(0),"C2"=character(0),"C3"=character(0),"C4"=character(0),"C5"=character(0), stringsAsFactors=FALSE)

len6<-data.frame("C1"=character(0),"C2"=character(0),"C3"=character(0),"C4"=character(0),"C5"=character(0),"C6"=character(0),stringsAsFactors=FALSE)

len7<-data.frame("C1"=character(0),"C2"=character(0),"C3"=character(0),"C4"=character(0),"C5"=character(0),"C6"=character(0),"C7"=character(0),stringsAsFactors=FALSE)

然后我们将select标签的value属性映射到状态的值。

更新了 Body.js ;

{ value: 'navigate', label: 'Navigate to <URL>' }