我正在使用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