我正在开发我的第一个React Native应用程序.我想要实现的是从父组件执行子函数,这是这样的情况:
儿童
- export default class Child extends Component {
- ...
- myfunct: function() {
- console.log('Managed!');
- }
- ...
- render(){
- return(
- <Listview
- ...
- />
- );
- }
- }
亲
- export default class Parent extends Component {
- ...
- execChildFunct: function() {
- ...
- //launch child function "myfunct"
- ...
- //do other stuff
- }
- render(){
- return(
- <View>
- <Button onPress={this.execChildFunct} />
- <Child {...this.props} />
- </View>);
- }
- }
在这个例子中,我想记录’Managed!’当我按下父类中的按钮时.它怎么可行?