我試圖循環對象數組。每個對象每天包含一個對象。我試圖看看,雖然數組捕獲Object.key(forEach數組索引),並在我記錄下它的每個值的關鍵。渲染一個包含對象的對象數組
DOPeration:[
{
'Monday':{
Closed:'Closed Today'
}
},
{ Tuesday:{
Closed:'Closed Today'
}
},
{ Wednesday:{
Closed:'Closed Today'
}
},
{ Thursday:{
Closed:'Closed Today'
}
},
{ Friday:{
Closed:'Closed Today'
}
},
{ Saturday:{
Closed:'Closed Today'
}
},
{ Sunday:{
Closed:'Closed Today'
}
}
]
export default class displayDay extends React.Component{
render(){
const thing = this.props.dates.map(function(sec,index) {
var keyVal = sec[Object.keys(sec)]
return(
<div key = {index}>
<h9>{Object.keys(sec)[0]}</h9>
<div>
{
for (var variable in keyVal) {
return(
<p>{variable}:{keyVal[variable]}</p>
)
}
}</div>
</div>
)
})
return(
<div className='container'>
<div className='box'>
{thing}
</div>
</div>
)
}
}
這樣的工作,但只有每天所以forin僅環捉住一個值
// const thing = this.props.dates.map(function(sec,index) {
// var keyVal = sec[Object.keys(sec)]
// for (var variable in (keyVal)) {
// console.log('keyVal',keyVal);
//
// return(
// <div key = {index}>
// <h9>{Object.keys(sec)[0]}</h9>
// <p>{variable}:{keyVal[variable]}</p>
// </div>
// )
// }
//
// })
// const的事情= this.props.dates.map(功能(秒,索引){// 變種KEYVAL =秒[Object.keys(秒)] //用於 (VAR變量(KEYVAL)){// 的console.log( 'KEYVAL',KEYVAL); // // 回報( //
{variable}:{keyVal[variable]}
//