2017-05-30 16 views
0
<Parent> /* event to fetch all refs value and submit */ 
    <Child> 
    <stateless function />/*this is all the refs sittin*/ 
    </Child> 
</Parent> 

親がどのように子どもからすべての参照を取得できるのか分かりませんか?事前に感謝しますreactjs親イベントのすべての子参照を取得します(handleSubmit)

+0

を、あなたは、例えば、入力したコードを追加し、outputratherあなた構造よりも期待できます。 –

答えて

1

私はそれがおそらく遅すぎるとあなたはすでに答えを知っていた。 あなたが必要とするのは、子供たちへの参照である "ref"です。 これを読むようなExposing DOM Refs to Parent Components

何か:

class Parent extends React.Component { 
    render() { 
    return (
     <div> 
     // this line will create a reference to the input text, 
     // inside the Child Component 
     // for example, if you want to get the value 
     // you can access `this.input.value` 
     <Child inputRef={(refToChild) => this.input = refToChild} /> 
     </div> 
    ) 
    } 
} 

class Child extends React Component { 
    render() { 
    return (
     <form> 
     // this line will call the Parent's function, 
     // creating a reference to the input text. 
     <input type="text" ref={props.inputRef} /> 
     </form> 
    ) 
    } 
} 
+0

答えをサポートするだけのリンクではなく、コード例で解決策の詳細を提供してください。 – Fabien

+0

改訂版の回答を確認してください。 – Win

+0

努力のためにUpvoted。 – Fabien

関連する問題