我正在构建一个评论应用程序。我正在使用 json-server 进行发布请求。我的数据库看起来像这样
[{
"id": 5,
"name": "Tom Cruise",
"image": "http://placeholder.pics/svg/300x200/000000",
"title": "Hiring Manager",
"employeeId": "22222222",
"funFact": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.",
"dateOfJoining": "04/12/2013"
},
{
"id": 6,
"name": "Julius Caesar",
"image": "http://placeholder.pics/svg/300x200/fdfdfd",
"title": "Sales Executive",
"employeeId": "33333333",
"funFact": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.",
"dateOfJoining": "04/12/2016"
}
]
这是我的添加操作
//Add Employee
export const addEmployee = employeeData => dispatch => {
axios
.post("http://localhost:3004/employees", {
employeeData,
headers: { "Content-Type": "application/json" }
})
.then(response =>
dispatch({
type: ADD_EMPLOYEE,
payload: response.data.employeeData
})
)
.catch(err => console.log(err));
};
这是我的减速机
case ADD_EMPLOYEE:
return {
...state,
employees: [action.payload, ...state.employees],
loading: false
};
一切正常。问题是它存储在数据库中的方式是这样的
{
"employeeData": {
"name": "Manpreet Sandhu",
"title": "bootstrap 4",
"funFact": "cccZCZCZ",
"image": "CZCZCZC",
"employeeId": "ZCZCZC",
"dateOfJoining": "C"
},
"headers": {
"Content-Type": "application/json"
},
"id": 7
}
我想删除每个条目之前添加的“employeeData”。