Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

107
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!