gpt4 book ai didi

javascript - React-native:this.navigator.pop 不工作

转载 作者:行者123 更新时间:2023-12-05 07:51:03 24 4
gpt4 key购买 nike

我是 react-native 的新手。我使用了 react-native-navbar 包回到之前的路线 navbar component for react-native

当我点击导航栏按钮时,它显示错误“undefined is not an object(evaluating 'this.navigator.pop')

这是我的代码片段:

'use strict';
var React = require('react-native');
var {
StyleSheet,
Text,
View,
} = React;
var NavigationBar = require('react-native-navbar');
var Demo = React.createClass({
render: function()
{
var leftButtonConfig = {
title: 'Back',
handler: function onNext() {
this.navigator.pop();
}
};

var titleConfig = {
title: 'Hello world page!',
};
return(
<View style={{ flex: 1, }}>
<NavigationBar
title={titleConfig}
leftButton={leftButtonConfig} />

<View style={styles.container}>
<Text style={styles.header}>
Hello World
</Text>
</View>
</View>
);
}
});
var styles = StyleSheet.create({
container: {
flex:1
},
header: {
fontSize: 20,
fontWeight: 'bold',
textAlign: 'center'
}
});

module.exports = Demo;

最佳答案

你只需要将它作为 prop 来调用即可。

正如他们在 example 中使用的那样

this.props.navigator.pop()

在路由导航时,导航用于作为 Prop 传递给组件,以便更轻松地弹出屏幕堆栈。顺便说一句,wix-navigation可以替代它,并且有很好的文档。

关于javascript - React-native:this.navigator.pop 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35593636/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com