如何更新或删除ngrx实体中的嵌套对象例如我想从(charter.entities.scopes.data)中删除第一个具有19个id的元素,如我的ngrx商店中存储的json对象中所示
charter: {
ids: [
1
],
entities: {
'1': {
id: 1,
projectName: 'Some Project',
projectCode: '899',
projectUniqueCode: '674a9596-50ee',
projectStatus: 'construction',
budgetCode: 'CC34',
projectTypeOne: 'Goods',
projectTypeTwo: 'New',
donorName: 'Elza Hills',
scopes: {
data: [
{
id: 19,
module: 'Miss Cassandra Cartwright I',
description: 'In tempore quia asperiores aut ea cum optio minima nemo est et aspernatur est repudiandae voluptas ipsum.',
time: '2018-01-23 15:37:36'
},
{
id: 43,
module: 'Leanne Douglas',
description: 'Occaecati facere eligendi esse esse nostrum in et vitae assumenda molestias omnis quis sit qui aut omnis est.',
time: '2018-01-23 15:37:36'
},
]
},
assumptions: {
data: [
{
id: 29,
assumption: 'Doloremque quo nihil minima ad optio perspiciatis asperiores debitis mollitia at debitis porro quia nam accusantium illo consequatur labore cum.',
comments: 'Inventore ut pariatur id laboriosam recusandae soluta quo sunt impedit aut velit.'
},
{
id: 164,
assumption: 'Dolores quam aut possimus sint fugiat natus quos quaerat saepe facilis harum molestiae.',
comments: 'Cumque quis magni illo dolore quas nam officiis dolores enim soluta doloribus in sed eum ut sunt.'
},
]
},
减速机
export interface State extends EntityState<ProjectsCharter> {
isLoading: boolean;
isLoaded: boolean;
selectedProjectsId: any;
}
export const adapter: EntityAdapter<ProjectsCharter> = createEntityAdapter({
selectId: (state: ProjectsCharter) => state.id,
sortComparer: false
});
export const initialState = adapter.getInitialState({
isLoading: false,
isLoaded: false,
selectedProjectsId: null
});
export function reducer(state = initialState, action: CharterActions) {
switch (action.type) {
case CharterActionTypes.loadCharterSuccess:
return {
...adapter.addOne(action.payload['data'], state),
isLoading: false,
isLoaded: true
};
case CharterActionTypes.updateScopeOnParent:
const scopeEntity = { ...state.entities[action.payload.param] };
scopeEntity.scopes.data = scopeEntity.scopes.data.map(item => {
if (item.id === action.payload.id) {
item.module = action.payload.module;
}
return item;
});
return {
...adapter.updateOne(scopeEntity, state)
};
default:
return {
...state
};
}
}
我可以使用这个 reducer 更新和修改 nestad 对象,但问题是 1- 它有点复杂,并且还在编译时在终端中显示error TS2339: Property 'map' does not exist on type 'Scope'.
我Argument of type '{ id: string; projectName: string; projectStatus: string; projectCode: string; projectUniqueCode:...' is not assignable to parameter of type 'Update<ProjectsCharter>'.