【问题标题】:How to use callback ref using ListView - ReactNative如何使用 ListView 使用回调引用 - React Native
【发布时间】:2016-06-01 16:47:39
【问题描述】:

我很难从 SectionHeader 访问 ref。我知道我需要使用 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>
 );
}

有人可以帮忙吗?

【问题讨论】:

    标签: javascript reactjs react-native ecmascript-6


    【解决方案1】:

    列表视图的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)}/>
    

    那么你就可以毫无问题地访问this._mylist了。

    【讨论】:

    • 非常感谢您的帮助和快速回复:)
    猜你喜欢
    • 2020-08-12
    • 2016-12-28
    • 1970-01-01
    • 2017-08-26
    • 1970-01-01
    • 1970-01-01
    • 2017-04-10
    • 1970-01-01
    • 2020-08-31
    相关资源
    最近更新 更多