2016-09-25 10 views
0

私は変更の選択ボックスのthis要素を取得しようとしています。
https://github.com/JedWatson/react-selectReactjs select - 入力の選択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(「この-propertyチェンジ」何、this) 'と' console.log( "val"、val) '出力? – Rashmirathi

+0

'イベント 'が必要ですか? –

+0

ここの 'this'要素は' react-select'要素ではないあなたの反応クラスです –

答えて

0

このタイプのハンドラを使用する方が良い方法は、bind(this)です。

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

ので、これは

あなたのコンポーネントになりますか、ターゲット要素にアクセスしたい場合に使用することができますが、参考文献やevent.target

関連する問題