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

108
Visualizações
How to declared a const inside a map function?

I have this computed function linhas() in VueJs, it fills the rows of my DataTable and I need open this function for assigning a value to "this.grupo" for example, so I don't need to use it the way I'm using in "this.maquinas".. And I don't know how to do this. I'm a begginer...

So basically I need a variable inside this function who keeps the group (this.grupo) values. What the best way to do it?

computed: {
    linhas () {
        return this.lista.map(row => ({
            href: { path: this.editRoute + row.id },
            cols: [
                row.id,
                row.tag,
                row.descricao,
                row.tipo === "ANALOGICA" ? "Analógica" : "Digital",
                this.grupo.find(g => g.id === row.id_grupo).nome,
                (this.maquinas.find(m => m.id === this.grupo.find(g => g.id === row.id_grupo).id_maquina) || { nome: "-" }).nome,
                "-"
            ]
        }));
    }
},
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Not 100% sure if that's what you're trying but you can simply get the right group once for each row:

//...
linhas() {
    return this.lista.map(row => {
        const group = this.grupo.find(g => g.id === row.id_grupo);
        return ({
            href: {path: this.editRoute + row.id},
            cols: [
                row.id,
                row.tag,
                row.descricao,
                row.tipo === "ANALOGICA" ? "Analógica" : "Digital",
                group.nome,
                (this.maquinas.find(m => m.id === group.id_maquina) || {nome: "-"}).nome,
                "-"
            ]
        });
    });
}
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