使用循环从另一个对象更新对象
Update an object from another object using a loop
我想更新另一个具有相应属性标识符的对象的属性。希望我能用一个循环来做到这一点,但由于我缺乏经验,我想不出该怎么做。
我不能只说
object1 = object2;
因为对象中的数组正在连接。
我目前拥有的是这样的:
if (direction === 'forw')
{
renderedCharts.electric.real.full = renderedCharts.electric.real.full.concat(newChartData.electric.real);
renderedCharts.electric.budget.full = renderedCharts.electric.budget.full.concat(newChartData.electric.budget);
renderedCharts.gas.real.full = renderedCharts.gas.real.full.concat(newChartData.gas.real);
renderedCharts.gas.budget.full = renderedCharts.gas.budget.full.concat(newChartData.gas.budget);
}
else if (direction === 'back')
{
for (var index in newChartData) // get the length of the arrays returned (all arrays will have the same number of elements
{
dataOffset += newChartData[index].real.length;
break;
}
renderedCharts.electric.real.full = newChartData.electric.real.concat(renderedCharts.electric.real.full);
renderedCharts.electric.budget.full = newChartData.electric.budget.concat(renderedCharts.electric.budget.full);
renderedCharts.gas.real.full = newChartData.gas.real.concat(renderedCharts.gas.real.full);
renderedCharts.gas.budget.full = newChartData.gas.budget.concat(renderedCharts.gas.budget.full);
}
但是CCD_ 1或CCD_。
使用排序
if (direction === 'forw')
{
for (var property in renderedCharts)
{
renderedCharts[property].real.full = renderedCharts[property].real.full.concat(newChartData[property].real);
renderedCharts[property].budget.full = renderedCharts[property].budget.full.concat(newChartData[property].budget);
}
}
else if (direction === 'back')
{
for (var property in newChartData)
{
dataOffset += newChartData[property].real.length;
break;
}
for (var property in renderedCharts)
{
renderedCharts[property].real.full = newChartData[property].real.concat(renderedCharts[property].real.full);
renderedCharts[property].budget.full = newChartData[property].budget.concat(renderedCharts[property].budget.full);
}
}
相关文章:
- 如果使用 lodash 将属性存在于另一个对象中,则向对象添加属性
- Javascript(Angular)从一个对象数组到第二个数组查找值
- 对一个对象使用reduce可以返回一个没有't在数组中包含目标字母
- AngularJS&JSON-从Previous&下一个对象
- jQuery$.inArray()总是返回-1和一个对象数组
- javascript处理一个对象数组以获得一个新的对象数组
- javascript函数,它接受两个输入:一个对象和一个键,并返回对象中该键的相应值
- 你能用来自数组的属性名称生成一个对象吗
- 预期响应包含一个对象,但在angular js中得到一个数组错误
- Protractor:element.getText()返回一个对象,而不是String
- 从knockout.js中的另一个对象更新一个深度结构化的javascript对象
- JavaScript - 创建一个函数,通过传递一个对象来更新变量
- 在节点 JS 中将值从一个对象更新到另一个对象
- 使用循环从另一个对象更新对象
- mongoDB-使用$set和一个对象更新文档
- 当另一个对象's属性被设置时,自动更新JavaScript对象属性
- KnockoutJS正在更新数组中的所有对象,而不仅仅是一个对象
- 通过匹配另一个对象的键值来更新一个对象的属性值
- 为什么更新一个对象中的属性会改变另一个对象
- 基于另一个对象更新JSON格式的JavaScript对象