你好,我正在尝试在我的导航器右按钮中绑定一个函数,但是出现了错误。
这是我的代码:
import React, { Component } from 'react';
import Icon from 'react-native-vector-icons/FontAwesome';
import Modal from 'react-native-modalbox';
import { StackNavigator } from 'react-navigation';
import {
Text,
View,
Alert,
StyleSheet,
TextInput,
Button,
TouchableHighlight
} from 'react-native';
import NewsTab from './tabs/news-tab';
import CustomTabBar from './tabs/custom-tab-bar';
export default class MainPage extends Component {
constructor(props) {
super(props);
}
alertMe(){
Alert.alert("sss");
}
static navigationOptions = {
title: 'Anasayfa',
headerRight:
(<TouchableHighlight onPress={this.alertMe.bind(this)} >
<Text>asd</Text>
</TouchableHighlight>)
};
render() {
return(
<View>
</View>
);
}
}
出现以下错误:
undefined is not an object (evaluating 'this.alertMe.bind')
当我在render函数中使用该方法时,它运行得很好,但在NavigationOption中无法处理它。我应该怎么做来解决这个问题。
this.props.navigation.setParams({ handleSave: this._saveDetails.bind(this) });
- a_rahmanshah