Display repertoire of item with recursive function in JS

Viewed 41

I need help to do a recursive function. Indeed I have an array of JSON objects that I call themes like this:

var themes = [{
   id:1,
   parent: 0,
   name: blabla,
   title: nanana,
   children: [
  {
    id: 2,
    parent: 1,
    name: chacha,
    title: lalala,
    children: [
      {
      etc....
      }
    ]
  }
]}]

What I want to do is that from an item list, I would like to display the name of the directory where the item is located. Example I have here my item list:

Item1 = [{name: myItem1, themeId: 1, comment: lilalalalaa}]
Item2 = [{name: myItem2, themeId: 2, comment: popopipi}]
Item3 = [{name: myItem3, themeId: 0, comment: fiffafaifia}]

var items = [Item1, Item2,Item3]

Now what I want is that after having to map and display my list items, I would like to also display the directory where each item is.

ex. : - myItem1 --- lilalalalaa  --- /nanana
      - myItem2 --- popopipi     --- /nanana/chacha
      - myItem3 --- fiffafaifia  --- /...

My problem is that I do not know how to make it dynamic directory display because I know that it can have several sub-themes (children).

I need your advice please.

0 Answers
Related