我有一個ListView,並試圖訪問我在renderRow中編寫的自定義組件的ref。我需要對自定義組件進行一些直接操作,所以我需要獲取這些參數的參考。React Native - 從renderRow獲取listview中的自定義組件的refs
好像其他人也遇到過這個問題。我試着按照React Native: Refs in ListView和https://github.com/facebook/react-native/issues/897的建議,但他們似乎不適合我。建議使用回調引用方法。但是,當我嘗試在componentDidMount中打印出this.refs.listView.refs時,它是空的,而不是返回customRef。我如何從renderRow函數獲取自定義組件的參考?謝謝
類具有以下功能:
componentDidMount() {
console.log(this.refs.listView.refs);
},
getRef() {
return 'customRef';
},
renderRow(rowData) {
return (
<CustomComponent ref={(ref)=>this.getRef} key={rowData.key} />
);
},
render() {
return (
<ListView
ref={'listView'}
dataSource={this.state.dataSource}
renderRow={this.renderRow} />
);
}