react-select multiple option

问题描述:

我试图设置react-select组件selectmultiple选项,但我不能让它工作,即使它是一切设置为文档说。当multifalse时,Select按照预期与一个value一起工作,但是当我设置multi={true}时,它显示valueundefinedreact-select multiple option

,当我在handleChange()event.target.value给它赋予undefined藏汉所以这就是为什么我刚刚使用event.value抢OBJ财产。我还是新手反应使约state任何提示会,如果我在这里做得不对-_-

class StatisticsFilter extends Component { 
    constructor(props) { 
    super(props); 
    this.state = {value: ''}; 

    this.handleChange = this.handleChange.bind(this); 
    } 
    handleChange(event) { 
    this.setState(event.value); 
    } 

const options = 
[ 
    { 
    value: 'foo', label: 'Foo' 
    }, 
    { 
    value: 'bar', label: 'Bar' 
    }, 
    { 
    value: 'baz', label: 'Baz' 
    } 
]; 

    render() { 
    return (
      <Select 
       value={this.state.value} 
       name="filter__statistics" 
       options={options} 
       onChange={this.handleChange} 
       multi={true} 
      /> 
    ); 
    } 
} 

使用react-select v. 1.0.0rc理解。

+0

可能的重复[从

+0

作为根据[本页](https://facebook.github.io/react/docs/events.html#overview)的说明,事件对象没有'value'属性。 – GJK

+0

@GJK好吧,它应该是'event.target.value',但是我收到未定义的值 – nehel

您的代码似乎存在一些问题。首先,onChange回调将直接传递给值,而不是事件。其次,一个对象必须传递给setState

您可以尝试将handleChange方法更改为以下代码吗?

handleChange(value) { 
    this.setState({ value }); 
} 

您也可以按照Multiselect使用的示例代码here

+1

的确,我所要做的就是将'even'参数改成'value' -_-应该去睡觉prooly – nehel