私は反応があり、私はthis.stateの中で誕生日をレンダリングする方法に固執しています。反応内の状態内のコンポーネントをどのようにレンダリングするのですか?
{this.state.birthdays}
しかし、それは各誕生日には達していないようです。私のgetElementByIDは、私のHTML上に存在するコンテナと等しいです。どんな助言/助けも素晴らしいだろう!
renderBirthdays: function(key) {
return (
<div key={key} index={key} details={this.state.birthdays[key]}>
{details.name} - {details.date}
</div>
)
},
render: function() {
return (
<div>{ Object.keys(this.state.birthdays).map(this.renderBirthdays) }</div>
)
}
だから、あなたのオブジェクトがかかりますjavascripts mapを利用することができます。このようrenderBirthdays
と呼ばれる関数を作成し、あなたのレンダリング機能の上に、その後
{ Object.keys(this.state.birthdays).map(this.renderBirthdays) }
をそして:
class App extends React.Component {
constructor(props) {
super(props);
this.state = {
birthdays: {
'January': [{
name: 'Mike',
date: '1/14/90'
}, {
name: 'Joe',
date: '1/7/92'
}],
March: [{
name: 'Mary',
date: '3/7/88'
}]
}
}
}
render() {
return (
<div>
</div>
);
}
}
ReactDOM.render(<App />,
document.getElementById('container'));
:
と表示されます。どのようにそれを表示しようとしていますか? –Object.keys
を使用して、月のキーの上にループが、その後、フラットな配列に誕生日の各セットを減らしますちょうど私の投稿の冒頭で、私は{this.state.birthdays}を使ってみたが、うまくいきませんでした。 –
あなたの部署では '{this.state.birthdays ['January'] [0]のようなことをします。 name} 'を使用するか、mapを使用して月をループし、そのようにデータを表示することができます。 –