【发布时间】:2020-08-14 08:14:11
【问题描述】:
您好,我的数组如下:
我的数组:
[
{
"Id": 72,
"PropertyId": 58,
"folderName": "test2",
"supportingDocs": [
{
"FilePath": "path",
"FileName": "green-logo.png",
"UploadedDate": "2020-04-29T15:00:41.423"
}
]
},
{
"Id": 71,
"PropertyId": 58,
"folderName": "test1",
"supportingDocs": [
{
"FilePath": "path",
"FileName": "red-logo.png",
"UploadedDate": "2020-04-29T15:00:41.423"
}
]
},
{
"Id": 70,
"PropertyId": 58,
"folderName": "test2",
"supportingDocs": [
{
"FilePath": "path",
"FileName": "orange-logo.png",
"UploadedDate": "2020-04-29T15:00:41.423"
}
]
}
]
如果 FolderName 相同,我想组合成一个并在 supportDocs 数组中添加两个常用文件夹 supportDocs 的数据,所以我希望 像这样输出:
[
{
"Id": 72,
"PropertyId": 58,
"folderName": "test1",
"supportingDocs": [
{
"FilePath": "path",
"FileName": "green-logo.png",
"UploadedDate": "2020-04-29T15:00:41.423"
}
]
},
{
"Id": 71,
"PropertyId": 58,
"folderName": "test2",
"supportingDocs": [
{
"FilePath": "path",
"FileName": "red-logo.png",
"UploadedDate": "2020-04-29T15:00:41.423"
},{
"FilePath": "path",
"FileName": "orange-logo.png",
"UploadedDate": "2020-04-29T15:00:41.423"
}
]
}
]
我尝试过使用 indexOf 但没有工作 如果文件夹名称相同,任何解决方案来分组数组
【问题讨论】:
标签: javascript json angular typescript