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

156
Views
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
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!