我正在开发我的第一个React Native应用程序.我想要实现的是从父组件执行子函数,这是这样的情况:
儿童
export default class Child extends Component {
...
myfunct: function() {
console.log('Managed!');
}
...
render(){
return(
<Listview
...
/>
);
}
}
Run Code Online (Sandbox Code Playgroud)
亲
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>);
}
}
Run Code Online (Sandbox Code Playgroud)
在这个例子中,'Managed!'当我按下父类中的按钮时,我想记录.它怎么可行?
react-native ×1