我正在使用React & SVG。在React中访问子元素的DOM节点
为了将子视图集中在子项<g>
上,我需要通过在子元素<g>
上调用getBBox()
API函数来获取'BBox'值。我的代码如下所示:
// <SVG> Element
const SVGParent = React.createClass({
componentDidMount : function(){
let eleBBox = ReactDOM.findDOMNode(this.refs.gEle).getBBox();
...
// Child <g> Element
const TemplateParent = React.createClass({
render : function(){
return(
<g ref = "gEle">
...
上面一行let eleBBox = ReactDOM.findDOMNOde(this.refs.gEle)
返回错误: TypeError: _reactDom2.default.findDOMNode(...) is null
事实上,在this.refs
内 'SVG' 元素是空着的OBJ。 如何访问子元素<g>
,以便我可以访问其DOM节点?
感谢,
感谢布拉德,我通过了第二个选项,揭露孩子的功能。 – Kayote