import React from 'react'
import ReactDOM from 'react-dom'
import AppReact from './app-react'
const data = [
{
id: 1,
title: 'item1',
round: [
{id: 1, total: 1000},
{id: 2, total: 2000}
]
},
{
id: 2,
title: 'item2',
round: [
{id: 1, total: 3000},
{id: 2, total: 4000}
]
},
{
id: 3,
title: 'item3',
round: [
{id: 1, total: 5000},
{id: 2, total: 6000}
]
},
{
id: 4,
title: 'item4',
round: [
{id: 1, total: 7000},
{id: 2, total: 8000}
]
},
{
id: 5,
title: 'item5',
round: [
{id: 1, total: 9000},
{id: 2, total: 10000}
]
},
{
id: 6,
title: 'item6',
round: [
{id: 1, total: 11000},
{id: 2, total: 12000}
]
},
{
id: 7,
title: 'item7',
round: [
{id: 1, total: 13000},
{id: 2, total: 14000}
]
},
{
id: 8,
title: 'item8',
round: [
{id: 1, total: 15000},
{id: 2, total: 16000}
]
}
]
ReactDOM.render(
<AppReact data={data} />,
document.getElementById('react-root')
)
import React from 'react'
class AppReact extends React.Component {
constructor(props) {
super(props)
console.log(props.data);
}
render() {
return (
<div>
{
this.props.data.map((item) => {
console.log('item', item);
return (
<div key={item.id}>
{item.title}
{item.round.map((r) => {
console.log('r', r);
return (
<div key={r.id}>
{r.total}
</div>
)
})}
</div>
)
})
}
</div>
)
}
}
export default AppReact;
const classes = {
0: 'first',
[props.data.length - 1]: 'last',
};
className={classes[i]}
.this.props.data.map((item, index) => {
let class = '';
if(index === 0) {
class='first'
}
if(index === this.props.data.length-1) {
class='second'
}
console.log('item', item);
return (
<div key={item.id} className={class}>
{item.title}
{item.round.map((r) => {
console.log('r', r);
return (
<div key={r.id}>
{r.total}
</div>
)
})}
</div>
)
})
import React from 'react'
export default data => (
<div>
data.map((item, index) => {
let class = '';
if(index === 0) {
class='first'
}
if(index === this.props.data.length-1) {
class='second'
}
return (
<div key={item.id} className={class}>
{item.title}
{item.round.map(r => (
<div key={r.id}>
{r.total}
</div>
) )}
</div>
)
})
</div>
)