1
我是Lodash的新手,我試圖用SQL作爲一個複雜的總和,但是我沒有找到任何解決方案。我試圖使用/組合多個Lodash函數而沒有成功。用Lodash總結和分組
我的要求是這樣的。我有一個JSON響應:
input =
[{"quantity":1067,"gross_revenue":4094.2,"date":"03","company":"Cat1","product":"Car"},
{"quantity":106,"gross_revenue":409,"date":"02","company":"Cat2","product":"Car"},
{"quantity":106,"gross_revenue":85,"date":"03","company":"Cat2","product":"House"},
{"quantity":106,"gross_revenue":100,"date":"02","company":"Cat3","product":"House"},
{"quantity":20,"gross_revenue":150,"date":"03","company":"Cat5","product":"Technology"},
{"quantity":40,"gross_revenue":100,"date":"01","company":"Cat5","product":"Technology"},
{"quantity":20,"gross_revenue":15,"date":"01","company":"Cat5","product":"Car"},
{"quantity":20,"gross_revenue":18,"date":"01","company":"Cat5","product":"House"},
{"quantity":20,"gross_revenue":2,"date":"01","company":"Cat2","product":"House"},
{"quantity":20,"gross_revenue":25,"date":"01","company":"Cat3","product":"House"}]
我需要如下產生的結果來填充系列的HighChart:
[{ name: 'Car', data: [15, 409, 4094.2] },
{ name: 'House', data:[45, 100, 85] },
{ name: 'Techonology', data:[100, null, 150] }]
這些值與結果:
- 製作使用帶標籤的產品組名稱
基於以下步驟,gen一箇中心提供全方位陣列與標籤數據
2.1總和基於產品和日期(所有現有的日期)
2.2包含空值,如果不存在收入總額爲任何現有
一天的毛收入2.3排序結果基於日期總收入,升序
這可能嗎?還是有另一種解決方案呢? 謝謝。
優秀@rphv感謝您的幫助。在您處理數組時,它也是解決方案的組合。我很困惑,因爲我試圖只使用Lodash。現在很清楚! – georgeos