I am trying to use map inside another map when creating a table for a word file using npm package docx.
The file is created, but when I try to open it in word it says that the file format is not supported. Everything works fine if I don't use the second map function so I know this is the problem.
This is what I have:
export const createTable = (items) => {
let loopTables = items.map((item1) =>
new Table({
columns: 5,
width: 0,
columnWidths: [2100, 1100, 1100, 1100, 1900],
layout: TableLayoutType.FIXED,
rows: [
new TableRow({
children: [
new TableCell({
children: [new Paragraph({
children: [
new TextRun({
text: `Main item ${item1[0].Group1}`,
}),
]
}),],
columnSpan: 5,
}),
],
}),
item1.map((item2) =>
new TableRow({
children: [
new TableCell({
children: [new Paragraph({
children: [
new TextRun({
text: `Nested item ${item2.Group2}`,
}),
]
}),],
columnSpan: 5,
}),
],
}),
)
]
}),
)
return loopTables
}
loopTables is then inserted in another file like this:
{
properties: {
type: SectionType.CONTINUOUS,
},
children: createTable(items) //Here we call the function that generates the table. It works fine without the nested map function.
},
Any idea whats wrong and what I should do to fix it?
Solved it by using two classic for loops instead. The rows was saved in two variables and then pushed togheter to an empty array. Don't know why the map didn't work though