即使使用扩展运算符

时间:2018-05-01 13:07:10

标签: angular rxjs ngrx

我使用Angular 5和ngrx与rxjs 5.5。 我在状态中有一个名为selection的属性,它是一个带有filters属性的对象。

在一个效果中,我试图在新变量'filters'中复制当前选择,并修改'something'属性。

当我运行代码时,我看到状态的选择切片被修改为效果中设置的值,即使我没有直接修改此切片并且我正在使用扩展运算符。

我也尝试过使用for循环而不是map,结果是一样的。

// effects.ts

// Initialise filters using the spread operator
const filters = [
       ...selection.filters // Taken from the store
];

// Filters is a list of objects of type {key: {something: string}}
filters.map(filter => {
    for (const key in filter) {
        if (filter.hasOwnProperty(key)) {
              filter[key].something = this.auxService.get(filter[key].something);
        }
    }
    // At this point selection.filters in the store has been modified
});

0 个答案:

没有答案