【发布时间】:2021-04-03 16:24:59
【问题描述】:
一个 JSON 数据有 2 个数组(类别和小程序),如下所示。每个小程序根据数据可以属于多个类别。
categories = ['Investments', 'Operations', 'Performance'];
applets = [
{
name: 'Performance Snapshot',
categories: ['Performance'],
},
{
name: 'Commitment Widget',
categories: ['Investments'],
},
{
name: 'CMS',
categories: ['Investments', 'Performance'],
},
];
我需要将该 JSON 数据转换为按类别使用它们,如下所示。如何在 Typescript 中执行此操作??
categories = [
{
'name': 'Performance',
'applets': ['CMS', 'Performance Snapshot']
},
{
'name' : 'Investments',
'applets' : ['Commitment Widget', 'CMS']
},
{
'name' : 'Operations',
'applets' : []
}
]
【问题讨论】:
标签: arrays json typescript keyvaluepair