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
你只需要檢查每個員工的所有複選框的值,這樣你會得到所有員工選擇的班次 –