0
我正在实施一个工人班次调度程序。见下面的截图:React多列选择复选框
我接收对象的从后端的阵列。第一个是员工名单
[{
"employeeId": "id",
"name": "bob"
},{
"employeeId": "id",
"name": "steve",
}]
;二是可用偏移:
[{"shiftStart":"00:00","shiftEnd":"08:00"},{"shiftStart":"08:00","shiftEnd":"15:00"},{"shiftStart":"15:00","shiftEnd":"00:00"}]
这是我创建的阵营组成:
class PlanningShiftManagement extends Component {
render() {
const availableShifts = this.props.shifts.map((shift) => {
return (
<th>
{shift.shiftStart} - {shift.shiftEnd}
</th>
)
})
const employees = this.props.employeeList.map((employee) => {
let employeecheckbox = this.props.shifts.map((shift) => {
return(
<td>
<input type="checkbox" />
</td>
)
});
return(
<tr className="table-row">
<td>{employee.title}</td>
{employeecheckbox}
</tr>
)
})
return(
<div>
<table className="scheduler-table">
<thead className="table-head">
<tr>
<th>Employee Name</th>
{availableShifts}
</tr>
</thead>
<tbody className="table-body">
{employees}
</tbody>
</table>
</div>
);
}
}
现在,我的问题是,我如何创建包含员工和所选班次的州。所以我想创建一个可以发送到后端的对象。
[{
"shiftStart": "20170313 10:00",
"shiftEnd": "20170313 17:00",
"employeeId": "id"
}]
你能更具体吗?您已经在后端拥有班次数据和员工数据,但是您希望您的React组件更改数据的“形状”并重新提交到后端?你是否可以控制数据如何保存在后端? – radiovisual
你只需要检查每个员工的所有复选框的值,这样你会得到所有员工选择的班次 –