我正在使用pivottable来创建和显示动态报告,我想知道有没有办法在json上的子数组中转动数据?
示例数据:
<script type="text/javascript">
// This example is the most basic usage of pivot()
var data = [
{
"accountId": "50000X",
"productId": 1,
"name": "PRODUCT A",
"sku": "SKU-A",
"fulfillmentSku": "SKU-A",
"friendlySku": "SKU-A",
"quantityStart": 19524,
"quantityEnd": 18523,
"activity": [
{
"eventType": "Assemby",
"createdOnUtc": "2018-01-26T00:00:00",
"quantity": -1
},
{
"eventType": "Deduction",
"createdOnUtc": "2018-01-26T00:00:00",
"quantity": -1500
},
{
"eventType": "Received",
"createdOnUtc": "2018-01-26T00:00:00",
"quantity": 500
}
]
},
{
"accountId": "50000X",
"productId": 97,
"name": "PRODUCT B",
"sku": "SKU-B",
"fulfillmentSku": null,
"friendlySku": "SKU-B",
"quantityStart": -22,
"quantityEnd": 48,
"activity": [
{
"eventType": "Assemby",
"createdOnUtc": "2018-01-26T00:00:00",
"quantity": 60
},
{
"eventType": "Received",
"createdOnUtc": "2018-01-26T00:00:00",
"quantity": 10
}
]
},
{
"accountId": "50000X",
"productId": 96,
"name": "PRODUCT C",
"sku": "SKU-C",
"fulfillmentSku": null,
"friendlySku": "SKU-C",
"quantityStart": 2755,
"quantityEnd": 2755,
"activity": []
},
{
"accountId": "50000X",
"productId": 95,
"name": "PRODUCT D",
"sku": "SKU-C",
"fulfillmentSku": null,
"friendlySku": "SKU-C",
"quantityStart": -11,
"quantityEnd": -6,
"activity": [
{
"eventType": "Assemby",
"createdOnUtc": "2018-01-26T00:00:00",
"quantity": 5
}
]
}
];
$(function () {
$("#output").pivot(data,
{
rows: ["productId", "name", "sku", "quantityStart", "quantityEnd"],
cols: ["activity"]
}
);
});
</script>
我想调整活动数据,活动中的所有内容都会被分组和计算 或者我是否必须更改我的json格式才能获得预期的输出?