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

161
Vistas
How to change a node in a recursive data object in in Vue.js

I have an object called tree with an items property, which recursively contains more items, shown with the types below.

type Tree = { items: Item[] }
type Item = { base: Base; items: Item[]  }
type Base = { category: string }

In Vue, I can create a new node or modify an existing one, but how can I assign this node to a place I choose?

  setItems(emitted: Emitted) {
  if (!this.tree) return;
  this.searchandReplaceNode(emitted, this.tree.items);
  console.log(this.tree.items)
  },
  searchandReplaceNode(emitted: Emitted, treeItems: Item[]) {
    let currentNode = treeItems;
    if (emitted.levels.length > 0) {
    console.log("searching " + emitted.levels[0]);
    //console.log(items);
    currentNode = treeItems[emitted.levels[0]].items;
    emitted.levels.shift();
    console.log("remaining levels: " + emitted.levels);
    this.searchandReplaceNode(emitted, currentNode);
  } else {
    console.log("levels consumed. assign emitted items to current node");
    currentNode = emitted.items;
  }
},

I have tried to use a level array, that tells me at what index to go deeper at each level.

Ultimately, I can get currentNode to be what I want, but I cannot get the relevant node in this.tree to be what I want.

about 4 years ago · Juan Pablo Isaza
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