【发布时间】:2016-10-12 00:42:52
【问题描述】:
我正在使用 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(...) is null
确实,'SVG' 元素中的 this.refs 是空 obj。
如何访问子 <g> 元素,以便访问其 DOM 节点?
谢谢,
【问题讨论】:
标签: javascript dom svg reactjs