zoukankan      html  css  js  c++  java
  • 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');
    }
  • 相关阅读:
    LeetCode124 二叉树中的最大路径和
    LeetCode100 相同的树
    LeetCode206 反转链表
    LeetCode460 LFU缓存
    LeetCode876 链表的中间结点
    hdu2767 强连通分量
    hdu1827 强连通分量
    模板 tarjan算法
    hdu2227 树状数组优化dp
    割点和桥
  • 原文地址:https://www.cnblogs.com/yuxingxingstar/p/9804170.html
Copyright © 2011-2022 走看看