zoukankan      html  css  js  c++  java
  • 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);
      }

    // ......
    // ......
    // ......
  • 相关阅读:
    Windows netsh命令的使用
    源码安装 qemu-2.0.0 及其依赖 glib-2.12.12
    .ko文件
    Suse环境下编译linux-2.6.24内核
    cut
    POJ3648 Wedding
    [Hnoi2010]Planar
    [中山市选2011]杀人游戏
    BZOJ3033 太鼓达人
    POJ1041 John's trip
  • 原文地址:https://www.cnblogs.com/wowchky/p/9133802.html
Copyright © 2011-2022 走看看