Table to json - TreeTable

UI Components for Angular
Post Reply
kardon
Posts: 1
Joined: 24 Jun 2018, 00:32

19 Mar 2020, 02:57

How do I transform a table for json to be used in treetable component with N levels?

Table structure:

Code: Select all

    categories: Category[] = [
    {  id: "1",  name: "Category 01",  parentId: "0" },
    {  id: "2",  name: "Category 02",  parentId: "1" },
    {  id: "3",  name: "Category 03",  parentId: "2" },
    { id: "4",  name: "Category 04",  parentId: "2" }
];
To:

Code: Select all

{
  "data": [
    {
      "data": {
        "id": "1",
        "name": "Category 01",
        "parentId": "0"
      },
      "children": [
        {
          "data": {
            "id": "2",
            "name": "Category 02",
            "parentId": "1"
          },
          "children": [
            {
              "data": {
                "id": "3",
                "name": "Category 03",
                "parentId": "2"
              }
            },
            {
              "data": {
                "id": "4",
                "name": "Category 04",
                "parentId": "2"
              }
            }
          ]
        }
      ]
    }
  ]
}

Post Reply

Return to “PrimeNG”

  • Information