[英]How to use callback ref using ListView - ReactNative
I am having hard times trying to access ref from SectionHeader. 我在尝试从SectionHeader访问ref时遇到困难。 I understand that I need to use ref as callback function instead of a string but I don't understand how to implement it.
我知道我需要使用ref作为回调函数而不是字符串,但是我不知道如何实现它。
render(){
return (
<ListView
ref="mylist"
dataSource={this.state.dataSource}
renderRow={this.renderCampaign}
style={styles.listView}
renderSectionHeader={this.header.bind(this)}
onChangeVisibleRows={this.updateFocus.bind(this)}/>
);
}
}
header(data){
return(
<MapView
ref="mymap"
style={styles.map}
region={this.state.region}
onRegionChange={this.onRegionChange.bind(this)}
showsUserLocation={true}
>
{this.state.markers.map(marker => (
<MapView.Marker
coordinate={marker.coordinate}
title={marker.name}
description={marker.reward_type}
/>
))}
</MapView>
);
}
Can someone help? 有人可以帮忙吗?
The ref callback attribute of your listview would look like this 您的listview的ref回调属性如下所示
<ListView
ref={(comp) => this._mylist = comp}
dataSource={this.state.dataSource}
renderRow={this.renderCampaign}
style={styles.listView}
renderSectionHeader={this.header.bind(this)}
onChangeVisibleRows={this.updateFocus.bind(this)}/>
Then you can access this._mylist
without any problem. 然后,您可以
this._mylist
访问this._mylist
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.