Zinou KIKO
Zinou KIKO

Reputation: 21

Convert JSON model to primeNg p-tree nodes Angular

I'm trying to use the tree component of PrimeNG https://www.primefaces.org/primeng/#/tree

I'm trying to convert an array of objects into an array of TreeNode, in order to be displayed like a tree.

My typescript model looks like this :

 [
  {
    "id": 1,
    "name": "family Product A",
    "description": "Description A",
    "items": [
      {
        "id": 2,
        "name": "Product AA",
        "description": "Description AA",
        "items": [],
        "type": 0
      },
      {
        "id": 3,
        "name": "Product AB",
        "description": "Description AB",
        "items": [],
        "type": 0
      }
  }

My JSON looks like this :

[{
            "key":1,
            "label":"family Product A",
            "data":"Description A",
            "expandedIcon":"pi pi-folder-open",
            "collapsedIcon":"pi pi-folder",
            "children":[
               {
                  "key":2,
                  "label":"Product AA",
                  "data":"Description AA",
                  "icon":"pi pi-file"
               },
               {
                  "key":3,
                  "label":"Product AB",
                  "data":"Description AB",
                  "icon":"pi pi-file"
               },

.......

Upvotes: 2

Views: 436

Answers (0)

Related Questions