我有一个这样的对象数组:
{
"sCode": "1010",
"PCode": "1011",
"category": "Diagnostic",
"procedure": "Oral assessment for patients up to the age of 3 years inclusive. ",
"serviceClassification": "First Dental Visit/Orientation",
},
我正在尝试按category
分组并创建一个名为children的数组,然后该数组具有另一个嵌套的serviceClassification
分组的子项数组
所需的输出
[
{
"id": "Diagnostic",
"text": "Diagnostic",
"children": [
{
"id": "FIRST DENTAL VISIT/ORIENTATION",
"text": "FIRST DENTAL VISIT/ORIENTATION",
"children": [
{
"id": 0,
"text": "01011 - Oral assessment for patients up to the age of 3 years inclusive."
}
]
}
我已经尝试了几个小时,这是我尝试过的代码示例:
答案 0 :(得分:1)
我首先将其按类别分组,然后按serviceClassification分组,剩下的转换工作留给您。