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');
}

react native navigationOptions中不能获取this的更多相关文章

  1. React Native工程中TSLint静态检查工具的探索之路

    建立的代码规范没人遵守,项目中遍地风格迥异的代码,你会不会抓狂? 通过测试用例的程序还会出现Bug,而原因仅仅是自己犯下的低级错误,你会不会抓狂? 某种代码写法存在问题导致崩溃时,只能全工程检查代码, ...

  2. React Native开发中自动打包脚本

    React Native开发中自动打包脚本 在日常的RN开发中,我们避免不了需要将我们编写的代码编译成安装包,然后生成二维码,供需要测试的人员扫描下载.但是对于非原生的开发人员来说,可能不知如何使用X ...

  3. React native开发中常见的错误

    react native环境搭建请移步:react native环境搭建 这里说说react native创建完成之后,运行中出现的常见问题, 问题1: java.lang.RuntimeExcept ...

  4. 用CodePush在React Native App中做热更新

    最近在学React Native,学到了CodePush热更新. 老师讲了两种实现的方法,现将其记录一下. 相比较原生开发,使用React Native开发App不仅能节约开发成本,还能做原生开发不能 ...

  5. react native( rn) 中关于navigationOptions中headerRight 获取navigation的问题 rn

    使用以下代码获取navigation static navigationOptions = ({ navigation, navigationOptions }) => { const { pa ...

  6. 组装者模式在React Native项目中的一个实战案例

    前言 在实际的开发中,如果遇到多个组件有一些共性,我们可以提取一个BaseItem出来,然后在多个组件中进行复用,一种方式是通过继承的方式,而今天我们要说的是另一种方式--组装者模式. 什么是组装者模 ...

  7. React Native 获取网络数据

    getMoviesFromApiAsync() { return fetch('http://facebook.github.io/react-native/movies.json') .then(( ...

  8. React Native(ios)项目中logo,启动屏设置

    由于logo和启动屏尺寸多,react native(ios)中没有命令可以自动生成各种的尺寸,所以可以使用以下办法:在ionic项目中生成(使用命令:ionic resources)后,再粘贴到re ...

  9. [转] 「指尖上的魔法」 - 谈谈 React Native 中的手势

    http://gold.xitu.io/entry/55fa202960b28497519db23f React-Native是一款由Facebook开发并开源的框架,主要卖点是使用JavaScrip ...

随机推荐

  1. AngularJS学习之旅—AngularJS 事件(十四)

    1.AngularJS 事件 ng-click ( 适用标签 :所有,触发事件:单击): ng-dblclick( 适用标签 :所有,触发事件:双击): ng-blur(适用标签 : a,input, ...

  2. Python基础之函数和模块

    函数的基本使用 函数的定义:把具有独立功能的代码块组织成一个小模块,在需要的时候调用.或者说,函数是组织好的,可重复使用的,用来实现单一,或相关联功能的代码段. 函数的使用:1.定义函数:2.调用函数 ...

  3. CentOS 7 最小安装网络配置

    通常最小安装是没有自动启动网络连接的,可以通过ifconfig或ip addr查看网络信息 (类似windows里的ipconfig),然而最小安装是没有ifconfig命令的, 这里我们使用ip a ...

  4. SpringBoot 中常用注解@PathVaribale/@RequestParam/@GetMapping介绍

    SpringBoot 中常用注解@PathVaribale/@RequestParam/@GetMapping介绍 本篇博文将介绍几种如何处理url中的参数的注解@PathVaribale/@Requ ...

  5. 基本MVVM 和 ICommand用法举例(转)

    引言 在本贴中,我们将学习WPF Commands. Commands 可以很好地与 MVVM 模式 (Model- View-ViewModel)结合在一起.我们也将看到,视图(view)实际上是怎 ...

  6. windows 和linux 路径解析的区别

    windows下使用的是“\”作为分隔符,而linux则反其道而行之使用"/"作为分隔符.所以在windows 环境中获取路径常见 C:\windows\system 的形式,而l ...

  7. 项目总结-timerTask的使用

    关于使用timerTask来进行定时任务的研究 业务说明:每天的0点执行一次 调用说明:com.hzmd.itest.db.ItestDbUtil中的startPermitTimer()方法进行最终的 ...

  8. fuser:command not found

    yum 安装fuser命令 yum install -y psmisc

  9. axios拦截http拦截

    一,判断登录页面 const routes = [ { path: '/', name: '/', component: Index }, { path: '/repository', name: ' ...

  10. mysql-笔记-默认值

    1 指定列的默认值 columnName int default '-1' 2 integer 列-设置自增列 也是指定默认值的方式 3 默认值必须是常量 不能使用函数.表达式---特例:timest ...