2016-11-19 8 views
0

私が割り当てたすべての参考文献のmeasure()を取得したいと考えています。これは私が管理しようとしているものです:refを配列に入れることは可能ですか?

<View 
    ref="dropZone[]"> 
</View> 
<View 
    ref="dropZone[]"> 
</View> 

lets dropZones = [] 
for(let i=0; i < refs.length; i++){ 
    this.refs[i].measure((ox, oy, width, height, px, py) => { 
     dropZones.push({x: px, y:py, height: height, width: width}) 
    } 
} 

これを管理するにはどうすればよいでしょうか?

+0

それは動作しますか?それが機能すれば - それはそうでなければ "最高"です。 – zerkms

+0

私はちょうどこのように例を示すようにしていました。それは小道具で配列を宣言することも可能ですか? –

+1

可能です - https://facebook.github.io/react/docs/refs-and-the-dom.html – zerkms

答えて

0

私はrender()で、このようにそれを行うには、管理矢印機能の使用:

<View 
    ref={c => this.dropZones.set(0, c)}> 
</View> 
<View 
    ref={c => this.dropZones.set(1, c)}> 
</View> 

をそして私はcomponentDidMount()でこれを使用:

Array.from(this.dropZones.values()) 
    .forEach(dropZone => { 
    dropZone.measure((ox, oy, width, height, px, py) => { 
     dropZonesArray.push({x: px, y:py, height: height, width: width}) 
    }) 
}) 
関連する問題