我有以下代码来迭代&为我的accordionData添加一些值;
var confPanels = {};
confPanels.accordionPanels = [];
confPanels.accordionPanels.length = 0;
self.get('accordionData').forEach(function(accordionData) {
var grid = {};
gridCols = self.gridParams(accordionData); // gridCols is returned as an object containing arrays
debugger; // Here when I come during the 2nd iteration, the earlier value in confPanels.accordionPanels[0].panel.props[0].value is overwritten to the new value (i.e. value corresponding to the 2nd iteration. Why is that so ?)
confPanels.accordionPanels.push({
panel: {
name: "my-grid",
props: [{
key: 'params',
value: gridCols
}]
}
});
});
我的问题是在迭代accordionData&调用gridParams()来获取相应的gridCols。
对于以下场景,我正在调试&在第二次迭代期间,confPanels.accordionPanels [0] .panel.props [0] .value中的较早值被覆盖为新值(即对应于第二次迭代的值。为什么会这样?)