我需要在一个数组对象中变换多个对象的数组, 我自己解释一下,我希望为每个表对带有相同“月”的对象进行分组,并通过在开头添加ID来替换具有相同值的属性: 例如: 数量:1 变为fpsIssuedQuantity(在camelCase中)。 http://jsfiddle.net/rLjQx/96589/
这是我的数据:
var data = {
"2018-01": [
{ id:"fpsIssued", month:"2018-01", quantity:"28" },
{ id:"dgfipIncome", month:"2018-01", amount:1350 },
{ id:"antaiPaidFps", month:"2018-01", quantity:2242 }
],
"2018-02": [
{ id: "fpsIssued", month: "2018-02", quantity: "29" },
{ id: "dgfipIncome", month: "2018-02", amount: 8530 },
{ id: "antaiPaidFps", month: "2018-02", quantity: 4857}
]
};
console.log(data);
和预期数据:
var expectedData = {
"2018-01": [
{ month: "2018-01", fpsIssuedquantity: "28",
dgfipIncomeamount: 1350, antaiPaidFpsQuantity: 2242
}
],
"2018-02": [
{ month: "2018-02", fpsIssuedquantity: "29",
dgfipIncomeamount: 8530, antaiPaidFpsQuantity: 4857
}
]
};
console.log(expectedData);
我使用lodash和angularjs,但我无法获得结果..请您能帮我吗?
答案 0 :(得分:0)
您可以将新对象与所需的新属性名称和值映射到新对象中。
axs
Subplot