上一部分返回 REACT 问题中的循环。
现在我可以像这样访问workers对象的每个属性:
workers[item][item2].firstName
根据这些数据,我想制作与TableRow
条目一样多的组件。
{isReady && Object.keys(workers).map(item =>{
// console.log(workers[item])
Object.keys(workers[item]).map(item2 =>{
console.log(workers[item][item2].job_name)
{
<TableRow
firstName={workers[item][item2].firstName}
lastName={workers[item][item2].lastName}
job_name={workers[item][item2].job_name}
hourly_rates = {workers[item][item2].hourly_rates}
fixed_fee={workers[item][item2].fixed_fee}
/>
}
})
})
}
或文本:
{
"data": [
{
"workerid": 2,
"firstName": "Vladimir",
"lastName": "Moskalev",
"ratesid": "mnt",
"idrates": 1,
"job_name": "mentor",
"hourly_rates": "7",
"fixed_fee": "0",
"jobcode": "mnt"
},
{
"workerid": 1,
"firstName": "Anton",
"lastName": "Buketov",
"ratesid": "mnt",
"idrates": 1,
"job_name": "mentor",
"hourly_rates": "7",
"fixed_fee": "0",
"jobcode": "mnt"
}
]
}
但什么也没发生
成分TableRow
import React from 'react'
const TableRow = ({firstName,lastName,job_name,hourly_rates,fixed_fee}) => {
return (
<tr>
<td>{ firstName } { lastName }</td>
<td>{ job_name }</td>
<td>{ hourly_rates }</td>
<td>{ fixed_fee }</td>
</tr>
)
}
export default TableRow