使用点差更新Ngrx存储中的修改后的值

时间:2019-04-18 05:13:23

标签: angular ecmascript-6 ngrx ngrx-store

我找不到在reducers状态下更新表动态键属性的正确方法。

我有一个带有动态键值的下表对象,我只需要使用扩展运算符更新当前状态下的已修改键值。

table: {
  "{DF9C5C2F-7163CCF15443}!A1": {
      id:"{DF9C5C2F-7163CCF15443}!A1", 
      address: "A1"      
   },
   "{DF9C5C2F-7163CCF15443}!B3": {
      id:"{DF9C5C2F-7163CCF15443}!B3", 
      address: "B3"      
   },
   "{DF9C5C2F-7163CCF15443}!D5": {
      id:"{DF9C5C2F-7163CCF15443}!D5", 
      address: "D5"      
   }
}

在这里,我只需要用新的修改值以下的状态更新上表对象中的第三行值

"{DF9C5C2F-7163CCF15443}!E5": {
      id:"{DF9C5C2F-7163CCF15443}!E5", 
      address: "E5"
   }```


it is adding a new record to the current state without updating the existing 3rd record, but I want to update the 3rd record only without adding as a new record in the state.

case TablesActionTypes.UPDATE_TABLE_REFERENCE_VALUES: {
const { payload: tableObj } = action as UpdateTableReferenceValue;
return {       
  ...state,      
  ...tableObj
  };           
};

please guide me how can achieve this using spread operator.

0 个答案:

没有答案