gpt4 book ai didi

javascript - 如何在react material-ui中获取密码字段值

转载 作者:数据小太阳 更新时间:2023-10-29 04:53:56 25 4
gpt4 key购买 nike

我无法访问 <TextField /> 的值, 如果我不写 <input type='password'/>然后它工作正常,但为此我得到一个类型错误,'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>
);}

}

下图是上述代码的控制台输出。

console output

最佳答案

这解决了我的问题:

<TextField ref='password'
hintText="Password"
floatingLabelText="Password"
type="password">
</TextField>

之后

 this.refs.password.getValue()

给出所需的输出。

For React v >= 15.6

<TextField ref={x => this.password = x}
hintText="Password"
floatingLabelText="Password"
type="password">
</TextField>

在 inputHandler 函数中

this.password.value

关于javascript - 如何在react material-ui中获取密码字段值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31446751/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com