我是Lodash的新手并试图解决这个问题,但可以找到一个好方法。
我有一系列订单和一系列行,每个订单都有一张票。
[{
"id": 201,
"order": "Buyer 1",
"lines": ▿[
▿{
"id": 1,
"ticket": ▿{
"id": 151,
"event": ▿{
"id": 31,
"name": "Event 1"
},
"name": "Event 1 Ticket 1",
"price": 39,
"minimum": 1,
"maximum": 5
},
"quantity": 1
},
▿{
"id": 2,
"ticket": {
"id": 152,
"event": {
"id": 31,
"name": "Event 1"
},
"name": "Event 1 Ticket 2",
"price": 60,
"minimum": 2,
"maximum": 4
},
"quantity": 5
},
▿{
"id": 3,
"ticket": {
"id": 153,
"event": {
"id": 33,
"name": "Event 1"
},
"name": "Event 3 Ticket 2",
"price": 60,
"minimum": 2,
"maximum": 4
},
"quantity": 5
}
],
"created_at": "2016-12-22T17:58:27+0000"
},
...]
[{
"event_id": 31,
"event_name":"Event 1",
"total_tickets": 6,
"total_sold": 339
"orders": [
{
"id": 201,
"order": "Buyer 1"
},
....
]},
{
"event_id": 33,
"event_name":"Event 3",
"total_tickets": 5,
"total_sold": 300
"orders":[
{
"id": 201,
"order": "Buyer 1"
}
]},
....
]
“total_tickets” - >订单'活动门票(数量)
的总和“total_sold” - >事件的订单总和(价格*数量)
答案 0 :(得分:0)
看看_.reduce
(甚至是vainilla JS Array.reduce
)
作为一个友好的建议,尝试想象和素描 - 在你的头脑或纸上 - 究竟需要用这些数据做什么,然后开始寻找工具来做,而不是相反。