Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

106
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda