当我没有将数据保存到数据库时,我可以添加或删除,一旦保存了数据并且我想通过删除它们或添加新值进行更新,就会出现此错误无法定义超过不可写长度的数组末尾的数组索引属性。如何解决此问题?
const handleDeleteDepartment = (companyIndex, departmentIndex) => {
if (departmentIndex !== 0) {
const newCompanies = [...companies];
newCompanies[companyIndex].children.splice(departmentIndex, 1);
setCompanies(newCompanies);
}
};