2016-07-27 32 views
0

我的代码中有一个例子,当您按下时可以切换到另一个页面。 这是第一部分:新闻TouchableOpacity不要切换到另一个页面

_onPress(projno){ 
    if(currentIndex == this.index){ 
     this.navigator.push({ 
     component:TeamDetailPage, 
     passProps:{projno:projno} 
     }) 
    } else { 
     return; 
    } 
    } 

这是第二部分:

<TouchableOpacity style={styleRow.item2} delayLongPress={300} onPress={() => this._onPress(this.props.projno)}> 
<Image style={{width:30,height:30}}source={HomeRankViewImgs[7]}/> 
<Text style={styleRow.teamName}>{this.shotna}</Text> 
</TouchableOpacity> 

我指的是成功的,写了下面的代码,但没有奏效: 这是第一部分:

_onPress(projno){ 
    if(currentIndex == this.index){ 
     this.navigator.push({ 
     component:TeamDetailPage, 
     passProps:{projno:projno} 
     }) 
    } else { 
     return; 
    } 
    } 

这是第二个部分:

<TouchableOpacity style={styleRow.item2} delayLongPress={300} onPress={() => this._onPress(this.props.projno)}> 
    <View style={teamInfoViewStyles.leftWrap}> 
     <Image style={teamInfoViewStyles.teamImg} 
     source={this.props.imgpath} /> 
     <View style={teamInfoViewStyles.infoWrap}> 
     <Text style={teamInfoViewStyles.teamName}> 
      {this.props.teamName} 
     </Text> 
     <Text style={teamInfoViewStyles.teamRank}> 
      {this.props.rank} 
     </Text> 
     </View> 
    </View> 
     </TouchableOpacity> 
+0

很抱歉,但你的解释不明确。该代码的哪部分不起作用,哪部分是? –

回答

0

尝试结合 “这一” 同时呼吁_onPress():

onPress = {this._onPress(this.props.projno).bind(这)}

相关问题