传播运算符并更新为数组

时间:2019-07-11 15:01:59

标签: javascript jquery ecmascript-6

我在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

0 个答案:

没有答案