【发布时间】:2017-02-08 21:35:30
【问题描述】:
我有两个非常简单的课程。我要做的就是从另一个组件调用一个方法,将文本打印到控制台。当用户单击类 2 中的导航按钮时,它应该调用类 1 中的 _printtest 函数,不幸的是,这没有发生。
第一类
class drawerControl extends Component {
constructor(props) {
super(props);
this._printtest = this._printtest.bind(this);
};
_printtest(){
console.log("Hello World");
}
render() {
return (
<Home
openControlPanel={this.openControlPanel.bind(this)}
functest={this._printtest}>
</Home>
);
}
}
第二类
class Home extends Component {
constructor(props){
super(props);
this.callPrint = this.callPrint.bind(this);
}
callPrint(){
this.props.functest()
}
render() {
return (
<TouchableHighlight onPress={this.callPrint} style= {styles.button}>
<Text>Navigate</Text>
</TouchableHighlight>
);
}
}
要么我得到一个错误,说“this.props.functest”不是一个函数,要么什么都没有发生。这看起来应该非常简单。我该怎么做才能解决这个问题?
【问题讨论】:
标签: javascript ios reactjs mobile react-native