2016-09-25 109 views
0

我想获取更改选择框的this元素。
https://github.com/JedWatson/react-selectReactjs选择 - 获取输入选择onChange

<Select 
    name="propertytype" 
    value={this.state.propertytype} 
    options={optionsPropertyType} 
    onChange={this.handlePropertyTypeChange} 
    placeholder="Property Type" 
/> 

我曾试图让this元素调用的处理。但onChange函数只是检索选择框的valuelabel

handlePropertyTypeChange: function(val) { 
    console.log("this -property change", this); 
    console.log("val", val); 
    this.setState({propertytypename: val.label}); 
    this.setState({propertytype: val.value}); 
    }, 
+0

做什么'的console.log(“本 - 属性变化” ,这个)'和'console.log(“val”,val)'输出? – Rashmirathi

+0

你需要'事件'吗? –

+0

这里'this'元素是你的反应类而不是'react-select'元素 –

回答

0

更好的方式来使用这种类型的处理程序是使用bind(this)。

onChange={this.handlePropertyTypeChange.bind(this)} 

所以这将是你的组件

,或者如果您要访问的目标元素可以使用反应裁判或event.target