Ana bileşenden çocuk işlevini çağırın İlk React Native uygulamasını geliştiriyorum.React Native
Çocuk
export default class Child extends Component {
...
myfunct: function() {
console.log('Managed!');
}
...
render(){
return(
<Listview
...
/>
);
}
}
Veli
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>);
}
}
Bu örnekte: Ne elde etmek çalışıyorum ebeveyn bileşeninden bir çocuk işlevi yürütmek için, bu durum ise Ebeveyn sınıfındaki düğmeye bastığımda 'Managed!'
'u günlüğe kaydetmek istiyorum. Bu nasıl uygulanabilir?
Ama 'execChildFunct' da başka şeyler yapmak zorundadır: Ben' bu çağırabilirsiniz. execChildFunct' içinde refs.child.myfunct'? Çünkü denedim ve işe yaramadı:/ – Pottercomuneo
Ref: this.props.children' için ref nasıl ayarlanır? – Mithril