我正在使用React和SVG技术。
为了将视图框位于子元素<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(...)为null
确实,在'SVG'元素内部的this.refs
为空对象。
我如何访问子元素<g>
,以便可以访问其DOM节点?
谢谢