onRightButtonPress
如何更新下一个组件的state
class Cell extends Component{
onResultsRef(resultsViewRef) {
console.log(resultsViewRef);
this._resultsView = resultsViewRef;// 这个地方赋值了
}
render(){
return(
<TouchableOpacity
style={{height: 75, backgroundColor:'white', flexDirection:'row'}}
onPress={()=>{
this.props.navigator.push({
component: shipDateInfo,
title: '船期详情',
passProps: {id: this.props.item.id.toString(), ref: this.onResultsRef,},
navigationBarHidden: false,
tintColor:'#444444',
leftButtonIcon: {uri:'icon_huijiantou', scale: 2},
onLeftButtonPress:()=>{
this.props.navigator.pop();
},
rightButtonIcon: {uri: 'icon_zf', scale:2},
onRightButtonPress:() => {
this._resultsView && this._resultsView.showModal() // 这里打印是undefined
}
})
}}
>
<View style={{width: width / 5 * 3, height: 75}}>
<View style={{flexDirection:'row'}}>
<Text style={{color: '#999999', marginTop: 17, marginLeft:12}}>空船期</Text>
<Image style={{width:14, height:14, marginLeft:12, marginTop:19}} source={{uri:'icon_shijian'}}/>
<Text style={{color: '#333333', marginTop: 17, marginLeft:6}}>{this.props.item.emptyBeginDate}</Text>
</View>
<View style={{flexDirection:'row'}}>
<Text style={{color: '#999999', marginTop: 17, marginLeft:12}}>空船港</Text>
<Text style={{color: '#333333', marginTop: 17, marginLeft:6}}>{this.props.item.emptyPortName}</Text>
</View>
</View>
<View style={{ height: 75}}>
<View>
<Text style={{color: '#333333', marginTop: 17}}>{this.props.item.shipTypeName}</Text>
</View>
<View>
<Text style={{color: '#333333', marginTop: 17}}>{this.props.item.deadweightTonnage}吨</Text>
</View>
</View>
</TouchableOpacity>
)
}
}
已经解决了, this变了.弄个变量接受一下this, 下面取值的时候用自己定义的this就好了