如何获取在formitem下的ref?

image.png

1.reactjs中提供了 ref属性来获取已经挂载元素的DOM节点,如下,给input添加ref属性

;

在其他函数中定位到该input并获取焦点。

let input = this.refs.username.refs.input
input.focus()

2.但是,如果标签被FormItem包裹的话,使用上述方法则获取不到DOM节点
解决方法:


     this.userzh = c}
           onBlur={(e)=>xxx}/>
    

获取

const input = this.userzh.refs.input
input.focus()

3.原理:直接在作为Form.Item子元素的Input上面增加ref属性会报错,因为FormItem里面的ref是个参数为Dom Component的回调函数。

参考:https://segmentfault.com/q/1010000007931844/a-1020000007936088

(完)

你可能感兴趣的:(如何获取在formitem下的ref?)