0
我使用Papa Parse將名稱,日期和結果的CSV文件轉換爲JSON對象,但我希望基於名稱的對象而不是CSV文件的行。如果這不可能使用Papa Parse,那麼我可以使用Angular(或Angular包)中的方法來執行此操作嗎?如何使用Papa Parse或Angular根據某個屬性合併對象?
我得到以下輸出:
[
{
name: 'foo',
date: '11-10-2016',
result: '10'
},
{
name: 'foo',
date: '12-10-2016',
result: '8'
},
{
name: 'bar',
date: '11-10-2016',
result: '1'
},
{
name: 'bar',
date: '15-10-2016',
result: '4'
}
]
但我想這樣的輸出:
[
{
name: 'foo',
results:
[
{
date: '11-10-2016',
result: '10'
},
{
date: '12-10-2016',
result: '8'
}
]
},
{
name: 'bar',
results:
[
{
date: '11-10-2016',
result: '1'
},
{
date: '15-10-2016',
result: '4'
}
]
}
]
我找到了答案如何與普通的JavaScript here做到這一點,但如果有一個函數來完成它在Papa Parse或Angular中更喜歡使用它。