首页 > 解决方案 > 扩展运算符并更新到数组

问题描述

我在 gridItems 中有一个来自服务器的数组列表,我创建了一个 & 使用扩展运算符的副本

let gridItems = this.get('sectionInformation.gridItems');
this.get('sectionInformation.someRows').pushObject(gridItems);
var updatedContainers = [...gridItems];
set(this.get('sectionInformation'), 'someRows', updatedContainers);

self.get('sectionInformation.someRows').forEach(function(container) {
    self._updateFieldsForSomeRows(container.fields);
});

_updateFieldsForSomeRows: function(fields, seqNum) {
    // Inside this, I do
    fields.forEach(function(field){
        set(field, 'someAttr', 'someVal');
    });
    //After above code is run, I expected that this should affect the fields inside sectionInformation.someRows. However, it instead updates in "gridItems". Not sure why that is the case
}

我的问题是出于某种原因,它只影响原始参考而不影响 sectionInformation.someRows

标签: javascriptjqueryecmascript-6

解决方案


推荐阅读