2016-09-11 4 views
1

私はむしろreact.jsに新しく、Reactでさまざまなコンポーネントのコレクションをレンダリングすることは可能でしょうか? は、例えば、私がこのように使用するプロパティのchildComponentsとContainerComponentクラスを持っている:ReactJs:動的なコンポーネントのコレクションをレンダリング

var childComponents = []; 

childComponents.push(<TextComponent text={this.props.text} />); 
childComponents.push(<PictureComponent src={this.props.image} />); 

return (
    <ContainerComponent 
     title={this.props.title} 
     innerComponents={childComponents} /> 
) 

だから、問題は、私はすべての単一の出力を生成するために、子コンポーネントを呼び出すループ内で機能をレンダリングすることができないということです子供。 ContainerComponentのメソッドをどのようにレンダーできますか?

ありがとうございます!あなたのようなすべてのコンポーネントが正常に行うだろう

答えて

0

場所:

render() { 
    return (
    <div> 
     {this.props.innerComponents} 
    </div> 
); 
} 

通常、次のコードでは、ニーズのために正常に動作する必要があります:

<ContainerComponent 
    title={this.props.title} 
> 
    <TextComponent text={this.props.text} /> 
    <PictureComponent text={this.props.image} /> 
</ContainerComponent> 
+0

は私のために働いていません。それは何もレンダリングしません。そして、私はエラーをキャッチすることはできません。 – SergB

+0

実現しました。地図は必要ありません。それがなぜ機能していないのか分かりません。 – vijayst

+0

this.props.childrenと似ています。 – vijayst

関連する問題