このようなjsonがあります(開発ツールインスペクタからコピー)
salePurchases
salesPeriods: Array[2]
0: Object
data: Array[5]
0: Object
1: Object
2: Object
3: Object
4: Object
period: "2011"
1: Object
data: Array[5]
0: Object
1: Object
2: Object
3: Object
4: Object
period: "2012"
purchasePeriods: Array[2]
0: Object
data: Array[5]
0: Object
1: Object
2: Object
3: Object
4: Object
period: "2011"
2: Object
data: Array[5]
0: Object
1: Object
2: Object
3: Object
4: Object
period: "2012"
私はそれを引き離して、このような新しいオブジェクトを作成したいと思います -
OrderedByYears:
2011:
data: Array[10]
0: Object // this should be the 1st item from the salesPeriods array with a period of 2011
1: Object // this should be the 1st item from the purchasePeriods array with a period of 2011
2: Object
3: Object
4: Object
5: Object
6: Object
7: Object
8: Object
9: Object // this should be the 5th item from the salesPeriods array with a period of 2011
10: Object // this should be the 5th item from the purchasePeriods array with a period of 2011
2012:
data: Array[10]
0: Object // this should be the 1st item from the salesPeriods array with a period of 2012
1: Object // this should be the 1st item from the purchasePeriods array with a period of 2012
2: Object
3: Object
4: Object
5: Object
6: Object
7: Object
8: Object
9: Object // this should be the 5th item from the salesPeriods array with a period of 2012
10: Object // this should be the 5th item from the purchasePeriods array with a period of 2012
キー「期間」に基づいて配置し、各配列を結合することを交互に行いますが、関連するオブジェクト salesPeriods と purchasePeriods を交互に使用します。
アンダースコアを使用すると、これは比較的簡単だと思います。それが簡単にできるかどうか誰でも知っていますか?関連する手順を説明していただければ幸いです。