admin管理员组文章数量:1320661
I try use last version of antd(3.10.0) and react(16.5.2).
I use the new way of ref according to .html
this.myRef = React.createRef();
when it rend,should like:
rend(){
<Select style={{ width: 200 }} ref={this.myRef}>
{Object.entries(this.state.catedict)
.map(en => <Option key={en[0]}>{en[1]}</Option>)}
</Select>
}
But when I want to get the value of Input or Select
I try to:
console.log(this.myRef.current.value);
But only get wrong result.
I find even:
console.log(this.myRef.current);
the result is:
t {props: {…}, context: {…}, refs: {…}, updater: {…}, saveSelect: ƒ, …}
context: {}
props: {style: {…}, children: Array(2), prefixCls: "ant-select", showSearch: false, transitionName: "slide-up", …}
rcSelect: t {props: {…}, context: {…}, refs: {…}, updater: {…}, onInputChange: ƒ, …}
refs: {}
renderSelect: ƒ (n)
saveSelect: ƒ (n)
state: null
updater: {isMounted: ƒ, enqueueSetState: ƒ, enqueueReplaceState: ƒ, enqueueForceUpdate: ƒ}
_reactInternalFiber: Na {tag: 2, key: null, type: ƒ, stateNode: t, return: Na, …}
__proto__: v
I want give the value of Select. How should I do?
I try use last version of antd(3.10.0) and react(16.5.2).
I use the new way of ref according to https://reactjs/docs/refs-and-the-dom.html
this.myRef = React.createRef();
when it rend,should like:
rend(){
<Select style={{ width: 200 }} ref={this.myRef}>
{Object.entries(this.state.catedict)
.map(en => <Option key={en[0]}>{en[1]}</Option>)}
</Select>
}
But when I want to get the value of Input or Select
I try to:
console.log(this.myRef.current.value);
But only get wrong result.
I find even:
console.log(this.myRef.current);
the result is:
t {props: {…}, context: {…}, refs: {…}, updater: {…}, saveSelect: ƒ, …}
context: {}
props: {style: {…}, children: Array(2), prefixCls: "ant-select", showSearch: false, transitionName: "slide-up", …}
rcSelect: t {props: {…}, context: {…}, refs: {…}, updater: {…}, onInputChange: ƒ, …}
refs: {}
renderSelect: ƒ (n)
saveSelect: ƒ (n)
state: null
updater: {isMounted: ƒ, enqueueSetState: ƒ, enqueueReplaceState: ƒ, enqueueForceUpdate: ƒ}
_reactInternalFiber: Na {tag: 2, key: null, type: ƒ, stateNode: t, return: Na, …}
__proto__: v
I want give the value of Select. How should I do?
Share Improve this question asked Oct 9, 2018 at 17:17 user504909user504909 9,55916 gold badges74 silver badges113 bronze badges2 Answers
Reset to default 5You can get it by the ref,the antd select is hoc of rc-select,if you want to get the value,you still get it by ref.rcSelect
`the react dom`
<Select ref={r => this.ctryListRef = r} />
`the js code`
console.log(this.ctryListRef.rcSelect.state.value)
by the rcSelect.state.value, you can get the value.
In addition, you can get antd textArea value, it's just another hoc~
save value of Select
on every change! and use it when you want.
<Select style={{ width: 200 }} onChange={(value)=>{
this.selectValue = value;
}}>
and use it in other place:
console.log('Select Value', this.selectValue)
本文标签: javascriptHow the get refs antd componement Select value of antdStack Overflow
版权声明:本文标题:javascript - How the get refs antd componement Select value of antd? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742065650a2418818.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论