【发布时间】:2022-01-08 13:37:26
【问题描述】:
我有两个 Json 对象。我想根据 Requirement_id 合并这些对象。第一个对象是需求的详细信息,另一个是匹配的详细信息。所以,我想将它与 Requirement_id 合并,如果有任何重复的类别值出现,我想将它合并到同一个 Requirement_id 下。 我正在使用 Nodejs14。
第一个对象
[
{
"Requirement_id": 1,
"Company_id": 884680,
"Requirement_name": "Requirement 1",
"Week_duration": 22,
"Week_must_time": 22,
"Hours_per_week": 22,
"Hours_per_month": 2,
"Hours_per_day": 2,
"No_of_resources": 22,
"Need_remote": "YES",
"Documents": null,
"Requirement_start": "2021-12-20",
"Requirement_end": "2021-12-30",
"Requirement_section": 1,
"Project_id": 2,
"Requirements_description": "sdsdsds",
"User_id": 423101,
"createdAt": "2021-12-10T15:00:48.000Z",
"updatedAt": "2021-12-10T15:00:48.000Z"
},
{
"Requirement_id": 2,
"Company_id": 884680,
"Requirement_name": "Application Designer",
"Week_duration": 3,
"Week_must_time": 3,
"Hours_per_week": 3,
"Hours_per_month": 3,
"Hours_per_day": 3,
"No_of_resources": 23,
"Need_remote": "YES",
"Documents": null,
"Requirement_start": "2021-12-15",
"Requirement_end": "2021-12-29",
"Requirement_section": 2,
"Project_id": 2,
"Requirements_description": "sdsdsd",
"User_id": 423101,
"createdAt": "2021-12-10T15:18:25.000Z",
"updatedAt": "2021-12-10T15:18:25.000Z"
},
{
"Requirement_id": 6,
"Company_id": 884680,
"Requirement_name": "Sr Application Designer Head",
"Week_duration": 3,
"Week_must_time": 3,
"Hours_per_week": 3,
"Hours_per_month": 3,
"Hours_per_day": 3,
"No_of_resources": 4,
"Need_remote": "YES",
"Documents": null,
"Requirement_start": "2021-12-20",
"Requirement_end": "2022-01-31",
"Requirement_section": 1,
"Project_id": 1,
"Requirements_description": "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.",
"User_id": 423121,
"createdAt": "2021-12-11T13:22:10.000Z",
"updatedAt": "2021-12-23T11:47:22.000Z"
},
]
第二个对象:
[
{ Requirement_id: 1, Category: 'Technology', Matching: 2 },
{ Requirement_id: 2, Category: 'Technology', Matching: 1 },
{ Requirement_id: 9, Category: 'Technology', Matching: 1 },
{ Requirement_id: 6, Category: 'Technology', Matching: 3 },
{ Requirement_id: 13, Category: 'Domain', Matching: 1 },
{ Requirement_id: 8, Category: 'Roles', Matching: 1 },
{ Requirement_id: 9, Category: 'Roles', Matching: 1 },
{ Requirement_id: 6, Category: 'Roles', Matching: 1 },
{ Requirement_id: 10, Category: 'Roles', Matching: 2 },
{ Requirement_id: 13, Category: 'Qualifications', Matching: 1 }
]
预期输出:
[{
"Category":"Technology",
"Matching":3,
"Requirement_id": 1,
"Company_id": 884680,
"Requirement_name": "Requirement 1",
"Week_duration": 22,
"Week_must_time": 22,
"Hours_per_week": 22,
"Hours_per_month": 2,
"Hours_per_day": 2,
"No_of_resources": 22,
"Need_remote": "YES",
"Documents": null,
"Requirement_start": "2021-12-20",
"Requirement_end": "2021-12-30",
"Requirement_section": 1,
"Project_id": 2,
"Requirements_description": "sdsdsds",
"User_id": 423101,
"createdAt": "2021-12-10T15:00:48.000Z",
"updatedAt": "2021-12-10T15:00:48.000Z"
},{
"Category":"Technology",
"Matching":1,
"Requirement_id": 2,
"Company_id": 884680,
"Requirement_name": "Requirement 1",
"Week_duration": 22,
"Week_must_time": 22,
"Hours_per_week": 22,
"Hours_per_month": 2,
"Hours_per_day": 2,
"No_of_resources": 22,
"Need_remote": "YES",
"Documents": null,
"Requirement_start": "2021-12-20",
"Requirement_end": "2021-12-30",
"Requirement_section": 1,
"Project_id": 2,
"Requirements_description": "sdsdsds",
"User_id": 423101,
"createdAt": "2021-12-10T15:00:48.000Z",
"updatedAt": "2021-12-10T15:00:48.000Z"
}]
【问题讨论】:
-
我不明白你想如何合并它们。如果
Requirement_id是 9 怎么办?我们如何在Technologies和Roles之间进行选择?