2016-08-16 162 views
1

嗨我试图在地图上显示标记的点击模式,但我看不出上标记点击任何模式任何人可以帮我出什么问题。我使用的模态,从https://github.com/maxs15/react-native-modalboxModal没有显示在react-native?

下面是代码:

import Modal from 'react-native-modalbox' 
openModal4(id) { 
    this.refs.modal4.open(); 
    } 

render(){ 
return(
<View style={style.mainContainer}> 
    <MapView 
     ref="map" 
     showUserLocation={true} 
     region={this.state.region} 
     onRegionChange={this.onRegionChange} 
     onRegionChangeComplete={this.onRegionChangeComplete} 
     style={styles.map} 
     rotateEnabled={false} 
     showsCompass={false} 
     > 
     {this.state.markers.map(function(marker){ 
     return(
      <MapView.Marker coordinate={marker.latlng} key={marker.id} onPress={this.openModal4} /> 
     ); 
     })} 
    </MapView> 
    <View style={{position: 'absolute', width: windowsWidth, height: windowsHeight - 100, alignItems: 'center', justifyContent: 'center'}}> 
     <Image 
     source={require('./assets/map-marker.png')} 
     /> 

    </View> 
    <Modal style={[styles.modal, styles.modal4]} position={"bottom"} ref={"modal4"}> 
    </Modal> 
    </View> 
) 
} 

任何人可以帮助我吗?提前致谢。

+0

你能显示文件中的所有代码吗? – stereodenis

+0

你可以看看现在@stereodenis – atif

+0

你用什么'延长React.Component'或'React.createClass'? – stereodenis

回答

0

你应该做出改变,结合这在回调中 看完这篇文章Don't Use Bind When Passing Props

openModal4 = (id) => { 
    this.refs.modal4.open(); 
} 
+0

我依然看不到模态,从底部到来? – atif

+0

你可以在openModal4中调用console.log(this.refs.modal4)吗? – stereodenis

+0

我看不到的console.log(this.refs.modal4) – atif

0

专家结合是其被使用箭头功能=> 这里后解决的问题是代码

openModal4(id){ 
    this.refs.modal4.open(); 
    } 

{this.state.markers.map((marker) => { 
      return(
       <MapView.Marker coordinate={marker.latlng} key={marker.id} onPress={this.openModal4} /> 
      ); 
      })} 

而你需要在构造函数中绑定函数,因为它包含'this'

this.openModal4 = this.openModal4.bind(this) 

希望我的奋斗会帮助别人