我一直在讨厌这个问题,而且它变成了一个无法正常工作的大黑客工作。我正在重新创建一个5个属性的对象和一个嵌套的对象数组。现在它不起作用。我制作的plunker有两个我正在使用的对象。它只显示结果中的一个,并且没有显示5个属性。在索引页面上,您将看到我开始使用的json。我需要最终结果包括原始数组加上每个细分对象中的chartBldArry,chartInvArry,chartLoeArry和chartLotsArry数组 plunker
var surveyTerritoryArry = [];
for (var i = 0; i < territory.subdivisions.length; i++) {
for (var i = 0; i < territory.subdivisions.length; i++) {
for (var i = 0; i < territory.subdivisions.length; i++) {
for (var i = 0; i < territory.subdivisions.length; i++) {
var territory = {
subdivisions : {
metrics: {
bld: {
count: {
custom: territory.subdivisions[i].metrics.bld.count.custom,
prod: territory.subdivisions[i].metrics.bld.count.prod
},
type: territory.subdivisions[i].metrics.bld.type
},
inv: {
fin: territory.subdivisions[i].metrics.inv.fin,
fut: territory.subdivisions[i].metrics.inv.fut,
mod: territory.subdivisions[i].metrics.inv.mod,
total: territory.subdivisions[i].metrics.inv.total,
uc: territory.subdivisions[i].metrics.inv.uc,
vdl: territory.subdivisions[i].metrics.inv.vdl,
},
loe: {
activity: territory.subdivisions[i].metrics.loe.activity,
bld: territory.subdivisions[i].metrics.loe.bld,
inv: territory.subdivisions[i].metrics.loe.inv,
size: territory.subdivisions[i].metrics.loe.size,
total: territory.subdivisions[i].metrics.loe.total,
},
lots: {
total: territory.subdivisions[i].metrics.lots.total,
total_active: territory.subdivisions[i].metrics.lots.total_active,
},
},
properties: {
id: territory.subdivisions[i].properties.id,
name: territory.subdivisions[i].properties.name,
show: territory.subdivisions[i].properties.show,
status: territory.subdivisions[i].properties.status,
territoryId: territory.subdivisions[i].properties.territoryId
},
type: territory.subdivisions[i].type,
chartBldArry: MapSidebarChartService.charBldDoughnut(territory.subdivisions[i]),
chartInvArry: MapSidebarChartService.charInvtDoughnut(territory.subdivisions[i]),
chartLoeArry: MapSidebarChartService.charLoeDoughnut(territory.subdivisions[i]),
chartLotsArry: MapSidebarChartService.charLotsDoughnut(territory.subdivisions[i])
}
};
surveyTerritoryArry.push(territory);
}
}
}
}
for (var i = 0; i < territory.length; i++) {
var territory = {
inv: territory[i].inv,
loe: territory[i].loe,
lots: territory[i].lots,
name: territory[i].name,
sbd: territory[i].sbd,
};
surveyTerritoryArry.push(territory);
};
console.log(surveyTerritoryArry)
答案 0 :(得分:2)
如果我理解你的问题,那么控制器中你需要的就是:
for (var i = 0; i < territory.subdivisions.length; i++) {
territory.subdivisions[i].charInvtDoughnut = MapSidebarChartService.charInvtDoughnut(territory.subdivisions[i]);
territory.subdivisions[i].charLoeDoughnut = MapSidebarChartService.charLoeDoughnut(territory.subdivisions[i]);
territory.subdivisions[i].charBldDoughnut = MapSidebarChartService.charBldDoughnut(territory.subdivisions[i]);
territory.subdivisions[i].charLotsDoughnut = MapSidebarChartService.charLotsDoughnut(territory.subdivisions[i]);
}