react native在static中使用this方法


方法一
首先需要在componentDidMount(){}中动态的添加点击事件

属性给params

componentDidMount(){ this.props.navigation.setParams({ title:'Save,
 navigatePress:this.clickSave }) }
clickSave = () => { alert('点击headerRight中的保存'); console.log(this.props.navigation); }
接下来就可以通过params方法来获取点击事件了
static navigationOptions = ({ navigation}) => ({ title: navigation.state.params.title, headerRight:( <Text onPress={() => navigation.state.params.navigatePress()}>
 保存 </Text> ) });
 方法二
let _this = null    // 在class之前定义 export default class MineScene extends Component {   static navigationOptions = ({ navigation }) => ({
    // ......       onPress={() => _this.clickSave() }
    // ...... })
  componentDidMount() {     _this = this }
  clickSave = () => {
    alert('点击headerRight中的保存');
    console.log(this.props.navigation);
  }

// ......
// ......
// ......

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM