2016-03-16 32 views
0

嗨,我正在使用反應和材料的UI。從材質UI文本字段中獲取自定義屬性onChangeHandler

的文本框的標記是這樣的

<TextField      
    floatingLabelText="Email" 
    onChange={this.props.onChange} 
    ref="email" 
    customAttr="customValue" 
    errorText = {this.props.errors.email} 
/> 

我onChange處理低於

function onChange(e) { 
    var customVal = e.target.getAttribute("customAttr"); 
    alert(customVal); //undefined 
} 

我想用材料的UI時,爲了獲得我的自定義屬性的值。

請幫助!

回答

0

你可以嘗試這樣的事情。

TextField

onChange={() => { this.props.onChange("customValue") }} 

或不ES6

onChange={function() { this.props.onChange("customValue") }} 

並更新onChange FUNC:

function onChange (customVal) { 
     alert(customVal) 
    }