0
是否有一個快速的方法,而不使用一系列複雜的for循環(使用類似Underscore的東西?或對我的MySQL查詢的改進?)採取我的數據,格式化在一個平坦的列表這樣的:平面MySQL查詢嵌套JSON對象
[
{
"J_NUM": "BOAK-1212",
"X_DUE_DATE": "2012-06-20T00:00:00.000Z",
"X_LEAD_TIME": 0,
"X_NAME": "Mail List Due",
},
{
"J_NUM": "BOAK-1212",
"X_DUE_DATE": "2012-06-08T00:00:00.000Z",
"X_LEAD_TIME": 0,
"X_NAME": "Vendor Specs 2",
},
{
"J_NUM": "JEFF-2000",
"X_DUE_DATE": "2012-06-11T00:00:00.000Z",
"X_LEAD_TIME": 0,
"X_NAME": "Client Final Approval",
},
{
"J_NUM": "JEFF-2000",
"X_DUE_DATE": "2012-06-08T00:00:00.000Z",
"X_LEAD_TIME": 0,
"X_NAME": "Vendor Specs 2",
}
]
而基於某些參數,在這種情況下J_NUM
,巢/組,以便它出來是這樣的:
[
{
"J_NUM": "BOAK-1212",
"SCHEDULE_SERIES": [
{
"X_DUE_DATE": "2012-06-20T00:00:00.000Z",
"X_LEAD_TIME": 0,
"X_NAME": "Mail List Due",
},
{
"X_DUE_DATE": "2012-06-08T00:00:00.000Z",
"X_LEAD_TIME": 0,
"X_NAME": "Vendor Specs 2",
}
]
},
{
"J_NUM": "JEFF-2000",
"SCHEDULE_SERIES": [
{
"X_DUE_DATE": "2012-06-11T00:00:00.000Z",
"X_LEAD_TIME": 0,
"X_NAME": "Client Final Approval",
},
{
"X_DUE_DATE": "2012-06-08T00:00:00.000Z",
"X_LEAD_TIME": 0,
"X_NAME": "Vendor Specs 2",
}
]
}
]
非常感謝你的幫助,但我一直在尋找的JavaScript的東西。我使用Underscore庫中的groupBy找到解決方案。 –