0
我有以下原始数据,并且我想汇总它以返回每个位置的总数,也可能是总计。使用Underscore汇总嵌套数据Js
位置A将是760
122(costPrice)* 4(数量)= 488(ALCATEL 5054)
136 * 2 = 272(DESIRE 530)
位置乙将300
104 * 2 = 208(ALCATEL 6060)
92 * 1 = 92(ALCATEL 7972)
总计:1060
如何可以执行使用下划线JS以下数据转换?
我开始这个plunker,但别以为我是在正确的方向前进...... http://plnkr.co/edit/ThvyQB3tm5KFuE6oLM1n?p=preview
原始数据:
[{
"location": {
"id": 82008938,
"name": "LOCATION A",
"phone": "",
"address": ""
},
"model": {
"id": 610214643353,
"name": "ALCATEL 5054",
"costPrice": 122,
"wholesalePrice": 127
},
"order": "5698",
"sim": [358848659378096]
}, {
"location": {
"id": 82009723,
"name": "LOCATION B",
"phone": "",
"address": ""
},
"model": {
"id": 610214648136,
"name": "ALCATEL 6060",
"costPrice": 104,
"wholesalePrice": 120
},
"order": "5698",
"sim": [358899043576662]
}, {
"location": {
"id": 82008938,
"name": "LOCATION A",
"phone": "",
"address": ""
},
"model": {
"id": 610214643353,
"name": "ALCATEL 5054",
"costPrice": 122,
"wholesalePrice": 127
},
"order": "5698",
"sim": [358885796982333]
}, {
"location": {
"id": 82009723,
"name": "LOCATION B",
"phone": "",
"address": ""
},
"model": {
"id": 610214648136,
"name": "ALCATEL 6060",
"costPrice": 104,
"wholesalePrice": 120
},
"order": "5698",
"sim": [358817108459730]
}, {
"location": {
"id": 82008938,
"name": "LOCATION A",
"phone": "",
"address": ""
},
"model": {
"id": 610214643353,
"name": "ALCATEL 5054",
"costPrice": 122,
"wholesalePrice": 127
},
"order": "5698",
"sim": [358879619289409]
}, {
"location": {
"id": 82008938,
"name": "LOCATION A",
"phone": "",
"address": ""
},
"model": {
"id": 610214643353,
"name": "ALCATEL 5054",
"costPrice": 122,
"wholesalePrice": 127
},
"order": "5698",
"sim": [358842400527891]
}, {
"location": {
"id": 82009723,
"name": "LOCATION B",
"phone": "",
"address": ""
},
"model": {
"id": 610214647597,
"name": "ALCATEL 7972",
"costPrice": 92,
"wholesalePrice": 95
},
"order": "5709",
"sim": [358842726462666]
}, {
"location": {
"id": 82008938,
"name": "LOCATION A",
"phone": "",
"address": ""
},
"model": {
"id": 610214646606,
"name": "DESIRE 530",
"costPrice": 136,
"wholesalePrice": 149
},
"order": "5710",
"sim": [358840719743714, 358848337490208]
}]
可能欲望的结果(可以是不同的格式,相同的数据和总数):
[{
"location": "LOCATION A",
"total": 760
}, {
"location": "LOCATION B",
"total": 300
}]
谢谢你的答复。虽然只有一个“DESIRE 530”实例,但价格是通过sim的长度(在这种情况下是2)来计算的,所以它将是136 * 2 = 272.对不起,如果我没有在问题中说清楚。但是我能够通过item.sim.length乘以costPrice来获得我所需要的。谢谢! – Ali