我正在尝试重新组织/重组我的数据以发送回api。我正在将值映射到它们各自的新属性中。
传入道具:
const data = [
{
otherProperty: "string",
otherPropertyTwo: "string",
personId: "1269",
peopleGroups: [
{ group: "SENIORS", groupStatus: "paid" },
{ group: "Infants", groupStatus: "not_paid" }
]
}
];
,并且需要对其进行重组,同时不要保留以下属性以外的任何其他属性:
const statusArrayUpdate = [{
"personid": "1269",
"groups": [
{
"group": "seniors",
"status": "paid"
},
{
"group": "Infants",
"status": "not_paid"
}
]
}]
我尝试了此操作,但是在第二个映射,groups属性上未定义...
const statusArrayUpdate = data.map(d => ({ ...d, personId: d.personId, groups: d.peopleGroups.map(s => [group: s.group, status: s.groupStatus]) }));
答案 0 :(得分:1)
您可以在 <plugin>
<groupId>net.masterthought</groupId>
<artifactId>maven-cucumber-reporting</artifactId>
<version>4.5.0</version>
<executions>
<execution>
<id>execution</id>
<phase>verify</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<projectName>ExecuteAutomation</projectName>
<inputDirectory>${project.build.directory}/jsonReports</inputDirectory>
<outputDirectory>${project.build.directory}/cucumber-report-html</outputDirectory>
<jsonFiles>
<!-- supports wildcard or name pattern -->
<param>**/*.json</param>
</jsonFiles>
</configuration>
</execution>
</executions>
</plugin>
数组上使用map
,只需取data
并重命名每个对象的personId
,然后将peopleGroups
重命名为{{ {} {1}}中的每个元素。
groupStatus