Vik*_*tya 6 javascript material reactjs
我无法访问的值<TextField />,如果我不写,<input type='password'/>那么它工作正常,但为此我得到一个TypeError,' this.refs [this._getRef(...)].getInputNode不是一个函数 ".
dialogAction(tag,e){
console.log(this.refs.password);
console.log(this.refs.password.getValue());
this.refs.dialog.dismiss();
}
render(){
let self = this;
let row = this.row,col = this.column;
let standardActions = [
{ text: 'Cancel',onTouchTap: this.dialogAction.bind(this,ProductConstants.CANCEL)},
{ text: 'Submit',onTouchTap: this.dialogAction.bind(this,ProductConstants.SUBMIT)}
];
return (
<div className="ProductRepository">
<Dialog ref = 'dialog'
title="Dialog With Standard Actions"
actions={standardActions}
actionFocus="submit"
modal={true}>
<TextField ref='password'
hintText="Password"
floatingLabelText="Password">
<input type="password" />
</TextField>
</Dialog>
</div>
);}
}
Run Code Online (Sandbox Code Playgroud)
下图是上述代码的控制台输出.
Kus*_*ain 18
对于材料1.0和反应16.1.1
使用inputRef
<TextField autoFocus={true} inputRef={el => this.fv = el}
placeholder="Required" size="30"></TextField >
Run Code Online (Sandbox Code Playgroud)
要读取下面的行使用值
console.log(this.fv.value);
Run Code Online (Sandbox Code Playgroud)
Vik*_*tya 13
这解决了我的问题:
<TextField ref='password'
hintText="Password"
floatingLabelText="Password"
type="password">
</TextField>
Run Code Online (Sandbox Code Playgroud)
之后
this.refs.password.getValue()
Run Code Online (Sandbox Code Playgroud)
给出所需的输出.
对于React v> = 15.6
<TextField ref={x => this.password = x}
hintText="Password"
floatingLabelText="Password"
type="password">
</TextField>
Run Code Online (Sandbox Code Playgroud)
在inputHandler函数中
this.password.value
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10439 次 |
| 最近记录: |