zoukankan      html  css  js  c++  java
  • React Native使用react-navigation时,设置navigationOptions中Static中使用this注意点

    使用react-navigation时,单页面设置navigationOptions中,进行Static中调用方法,不能像以下设置

    onPress = {()=>this.clickFinishButton()}
    export default class extends Component {
      static navigationOptions = ({
        navigation,
        screenProps
      }) => ({
        headerTitle: 'List实现多选',
        headerTitleStyle: {
          color: 'white'
        },
        headerStyle: {
          backgroundColor: Color.kMainColor // 设置导航栏的背景颜色,headerTintColor设置无效
        },
        headerRight:(
            <NavigationItem
                title='完成'
                // 这里注意: static里面不能使用this调用方法,出现clickFinishButton is not function
                // 参考博客: http://www.jianshu.com/p/2f575cc35780
                // onPress={()=>navigation.state.params.navigatePress()}
                onPress = {()=>this.clickFinishButton()}
            />
        )
      });

    解决方法:

    export default class extends Component {
      static navigationOptions = ({
        navigation,
        screenProps
      }) => ({
        headerTitle: 'List实现多选',
        headerTitleStyle: {
          color: 'white'
        },
        headerStyle: {
          backgroundColor: Color.kMainColor // 设置导航栏的背景颜色,headerTintColor设置无效
        },
        headerRight:(
            <NavigationItem
                title='完成'
                // 这里注意: static里面不能使用this调用方法,出现clickFinishButton is not function
                // 参考博客: http://www.jianshu.com/p/2f575cc35780
                onPress={()=>navigation.state.params.navigatePress()}
                // onPress = {()=>this.clickFinishButton()}
            />
        )
      });
    componentDidMount(){
        // 处理数据源
        this.handlerDataSource();
        this.props.navigation.setParams({navigatePress:this.clickFinishButton})
      }
      // 点击完成按钮
      clickFinishButton = ()=> {
          alert('哈哈');
        //   let data = this.state.dataArr;
        //   let selectResultArr = [];
        //   for (var index in data) {
        //         var element = object[index];
        //         if (element.isSelected) {
        //             selectResultArr.push(element);
        //         }
        //   }
        //   alert(selectResultArr.length);
      }
  • 相关阅读:
    绝对定位position: absolute;
    加号选择器(ul>li + li)
    position: absolute;绝对定位水平居中问题
    nth-child 和 nth-of-type 的区别
    Scrapy Shell 待续。。。
    TypeError: write() argument must be str, not bytes
    ModuleNotFoundError :No module named 'win32api'
    scrapy 简介
    3月27下午(补交)
    软件工程作业二:需求分析
  • 原文地址:https://www.cnblogs.com/pengsi/p/7088401.html
Copyright © 2011-2022 走看看