Tôi đang cố gắng sử dụng NavigatorIOS
như vậy trong index.ios.js
của tôi tôi nhận:Phản ứng Native, NavigatorIOS, không xác định không phải là một đối tượng (đánh giá 'this.props.navigator.push')
'use strict';
var React = require('react-native');
var Home = require('./App/Components/Home');
var {
AppRegistry,
StyleSheet,
NavigatorIOS
} = React;
var styles = StyleSheet.create({
container:{
flex: 1,
backgroundColor: '#111111'
}
});
class ExampleApp extends React.Component{
render() {
return (
<NavigatorIOS
style={styles.container}
initialRoute={{
title: 'example',
component: Home
}} />
);
}
};
AppRegistry.registerComponent('exampleapp',() => ExampleApp);
module.exports = ExampleApp;
Và sau đó trong Home.js
:
'use strict';
var React = require('react-native');
var Park = require('./Park');
var {
View,
StyleSheet,
Text,
TouchableHighlight
} = React;
var styles = StyleSheet.create({
...
});
class Home extends React.Component{
onPress() {
this.props.navigator.push({
title: 'Routed!',
component: Park
});
}
render() {
return (
<View style={styles.mainContainer}>
<Text> Testing React Native </Text>
<TouchableHighlight onPress={this.onPress} style={styles.button}>
<Text>Welcome to the NavigatorIOS . Press here!</Text>
</TouchableHighlight>
</View>
);
}
};
module.exports = Home;
vấn đề là tôi có khi tôi click vào TouchableHighlight
kích hoạt onPress()
, tôi nhận được một lỗi:
"Error: undefined is not an object (evaluating 'this.props.navigator')
Vì vậy, có vẻ như nó không thể tìm thấy các navigator
từ đạo cụ nhưng hoa tiêu nên được thông qua bởi NavigatorIOS
?
Cũng có vẻ như rằng Component Home
có this.props.navigator
theo hình ảnh:
Bất kỳ gợi ý?
Tôi tìm thấy một vài liên kết (người có chính xác cùng một vấn đề nhưng điều đó không hiệu quả):
Đúng vậy! Nghĩ rằng nó phải làm với 'NavigatorIOS'! Cảm ơn Dave! – manosim
Nếu bạn đang sử dụng ES7 trang trí, bạn cũng có thể sử dụng autobind: https://github.com/andreypopp/autobind-decorator –
Cảm ơn rất nhiều nó đã được giúp đỡ – Simcha