2

I'm using PrimeNG treetable component and I want to get all the children of a node when I click on getChildrens button near that node.

Also, I want to get all the parents of that node when I click the getParents button near the same node.

The goal is to give a different style to the children and parents of the node once I select the appropriate button.

Is PrimeNG treetable offer that functionnality to get all the children and parents of a node ?

Kivo
  • 385
  • 8
  • 24

1 Answers1

0
    getParent(node, arr) {
        if (node && node.label) {
          let result;
          arr.unshift({
            key: node.tag,
            value: node.label,
            data: node.data
          })
          
          if (node.parent) {
            result = this.getchildren(node.parent, arr)
          } else {
            result = arr 
          }
          return result
        } else {
          this.initdata.ancestorValue = []
          arr = []
        }
    
      }
      getchildren(node, arr) {
        if (node && node.label) {
          let result;
          arr.unshift({
            key: node.tag,
            value: node.label,
            data: node.data
          })
          if (node.parent) {
            result = this.getParent(node.parent, arr)
          } else {
            result = arr 
          }
          return result
        }
        return arr      
    
      }

console.log(this.getParent(event.node,[]) 
  • 2
    Please don't post only code as an answer, but also provide an explanation of what your code does and how it solves the problem of the question. Answers with an explanation are usually more helpful and of better quality, and are more likely to attract upvotes – Ran Marciano Mar 03 '21 at 08:05