我有以下代码:
static navigationOptions = {
headerTitle: 'Screws',
title: 'Screws',
headerRight:
<TouchableOpacity onPress={() => {
this.changeVisibilityFilterModal(true);
}}>
<Image style={{marginRight:10}} source={require('../../assets/img/icFilter.png')}/>
</TouchableOpacity>,
};
changeVisibilityFilterModal(visibility){
setState({filterModalVisible: visibility});
}
问题是我无法在navigationOptions中访问changeVisibilityFilterModal。任何人都知道我如何能够调用该方法并解释为什么它不能像当前那样起作用!
最佳答案
您不能直接从静态方法中调用changeVisibilityFilterModal
,因为它是class method
。
static navigationOptions = ({navigation}) => ({
headerTitle: 'Screws',
title: 'Screws',
headerRight:
<TouchableOpacity onPress={() => {
navigation.state.params.visibilityFunc(true);
}}>
<Image style={{marginRight:10}} source={require('../../assets/img/icFilter.png')}/>
</TouchableOpacity>,
})
componentDidMount() {
this.props.navigation.setParams({ visibilityFunc: this.changeVisibilityFilterModal });
}
changeVisibilityFilterModal = (visibility) => {
this.setState({filterModalVisible: visibility});
}
关于javascript - 未定义不是函数(评估'_this4.changeVisibilityFilterModal(true)),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/49959190/