【发布时间】:2019-11-11 03:02:24
【问题描述】:
我有以下状态结构:
{ entities:
1: {name: "Basketball", id: "1", leagues: Array(3)}
2: {name: "Volleyball", id: "2", leagues: Array(3)}
3: {name: "Soccer", id: "3", leagues: Array(0)}
}
现在我只想删除一个 ID 为“3”的项目。
以下不起作用:
const state = ctx.getState();
delete state.entities[action.id];
ctx.setState(
patch<SportTypeStateModel>({
entities: {...state.entities},
IDs: state.IDs.filter(id => id !== action.id)
})
);
它会抛出以下错误:
`ERROR TypeError: Cannot delete property '3' of [object Object]`
这样做的正确方法是什么?
【问题讨论】:
-
您的结构似乎缺少括号。什么是“实体”?
标签: angular typescript redux ngxs