我需要嵌套分组方面的帮助。我目前正在学习高级图表,这是我需要格式化名称和类别键值对。
我想按学校,性别和课程对数据进行分组。以下是我的json代码。
[{"school":"Sunway","gender":"female","course":"BCS","Total":2},
{"school":"Sunway","gender":"male","course":"BCS","Total":1},
{"school":"Sunway","gender":"female","course":"BICT","Total":1},
{"school":"Swinburne","gender":"female","course":"BCS","Total":2},
{"school":"Swinburne","gender":"male","course":"BCS","Total":3},
{"school":"Swinburne","gender":"female","course":"BICT","Total":1},
{"school":"Swinburne","gender":"male","course":"BICT","Total":2},
{"school":"UCTS","gender":"male","course":"BCS","Total":3},
{"school":"UCTS","gender":"female","course":"BICT","Total":1},
{"school":"UCTS","gender":"male","course":"BICT","Total":2}]
预期结果:
[{
name: "Sunway",
categories: [{
gender: "female",
categories: ["BICT", "BCS"]
}, {
name: "male",
categories: ["BICT", "BCS"]
}]
}, {
name: "Swinburne",
categories: [{
name: "female",
categories: ["BICT", "BCS"]
}, {
name: "male",
categories: ["BICT", "BCS"]
}]
}, {
name: "UCTS",
categories: [{
name: "female",
categories: ["BICT", "BCS"]
}, {
name: "male",
categories: ["BICT", "BCS"]
}]
}]
谢谢!!非常感谢!!