Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

294
Visualizações
How to use map inside map using docx npm (javascript)

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?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

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

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda