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

157
Visualizações
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 à 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