• react native navigationOptions中不能获取this


    static navigationOptions = ({ navigation, navigationOptions,screenProps }) => {
    const { params } = navigation.state;
    return {
    tabBarVisible: true,
    headerRight:(
    <View>
    <TouchableOpacity onPress={()=>navigation.state.params.navigatePress()}>
    //this.order()
    <View style={{marginRight:30/1536*width}}>
    <Text style={styles.hadlesub}>点餐</Text>
    </View>
    </TouchableOpacity>
    </View>
    )
    }
    };

    // 点击完成按钮
    order = ()=> {
    alert('haha');
    }

    componentDidMount() {
    // 处理数据源
    this.props.navigation.setParams({navigatePress:this.order})
    }

    方法二:

    在最外部声明:
    let that;
    在class内部:
    constructor(props){
            super(props);
            that = this;
    }
    在const * = StackNavigation({})中:
    static navigationOptions = ({ navigation, navigationOptions,screenProps }) => {
    const { params } = navigation.state;
    return {
    tabBarVisible: true,
    headerRight:(
    <View>
    <TouchableOpacity onPress={() => that.order()}>
    <View style={{marginRight:30/1536*width}}>
    <Text style={styles.hadlesub}>点餐</Text>
    </View>
    </TouchableOpacity>
    </View>
    )
    }
    };

    order = ()=> {
    alert('haha');
    }
  • 相关阅读:
    元组,字典
    python字符串
    tensorflow 学习笔记
    tensorflow example1
    python第二章(2)列表
    python3.5学习第二章(1)标准库,bytes
    类加载过程
    数据值与地址值
    类的初始化与实例化顺序
    SpringCloudBus
  • 原文地址:https://www.cnblogs.com/yuxingxingstar/p/9804170.html
Copyright © 2020-2023  润新知