2016-08-18 10 views
3

でに関数を渡すために、親は子供が親の機能を呼び出したい場合は、私は次の操作を行うことができ、ネイティブに反応することができますどのようにネイティブリアクトは子供

onpress=this.props.myFunc(); 

どのように私はpassPropsを通じてナビゲーターとNavigatorIOSでこれを達成することができます:子供はそうのようなその関数を呼び出すでしょうか?

<NavigatorIOS 
    initialRoute={{ 
     component: MyScene, 
     title: 'My Initial Scene', 
     passProps: { myProp: this.handleChildFunc.bind(this) } // Not work 
     passProps: { myProp:()=>this.handleChildFunc.bind(this) } //Not work 
    }} 
    style={{flex: 1}} 
    /> 

更新

返事のおかげで、私はネイティブ反応する新たなんだ、本当にnavigatorIOSに答えの下に実装する方法を理解していません。しかし、私は、次を試してみましたが、子供が成功demoが、多分役に立つ存在である子

this.props.handleFunc(); 

答えて

1

で小道具

passProps: { parentFunc:()=>this.handleFunc() } 

としてコールバックを渡し、親は親の機能

を呼び出すことができます。 renderScene機能の

例:新しいシーンを押す

renderScene(route, navigator) { 
    let Component = route.component; 
    return <Component {...route.params} navigator={navigator} /> 
} 

例:

this.props.navigator.push({ 
    component: Child, 
    func: customFunc 
}) 

、あなたは子ページ(二次ページ)にthis.props.funcを使用することができます。

+0

感謝。 – bns

2

このコードの仕事はあなたの答えのための私のために

return(
    <NavigatorIOS 
     initialRoute={{ 
      component: MyScene, 
      title: 'My Initial Scene', 
      myProp: (() => { this.handleChildFunc.bind(this) }) // work 
     }} 
     renderScene={ (route, navigator) => 
      <Child navigator={navigator} {...route.passProps} onFun={ route.myProp } /> 
     } 
     /> 
) 

コール子で

this.props.onFun() 

Check here

+0

あなたの答えをありがとう。 – bns