1

I have created created a dictionary from Django-mptt and used json.dump() to get the JSON object.

{
  "a": "cat1",
  "c": ["item2", "item1"],
  "b": [
    {"a": "burgers", "c": [], "b": []},
    {"a": "south indian", "c": [], "b": []},
    {"a": "veg subs", "c": ["corn and peas", "a;loo patty", "paneer delite"], "b": []},
    {"a": "traditional", "c": ["subway melt", "Chicken ranch", "turkey", "Subway club"], "b": []},
    {"a": "favourites", "c": ["tuna", "chicken ham", "roasted chicken"], "b": []},
    {"a": "beverages", "c": [], "b": []},
    {"a": "north indian", "c": [], "b": []},
    {"a": "oriental", "c": [], "b": []},
    {"a": "european ", "c": [], "b": []}
  ]
}

Here, "cat1" is the main category, having sub-categories children, burgers, traditional, favourites etc. Any category can have sub-categories.

  • a - Category name
  • c - Items list
  • b - Children

This is my JSON object. What do I use to show this JSON object in tree format in JavaScript. I need to display the First children of the every category clicked. And for every Category clicked, I want to display the items below the tree structure.

georgebrock
  • 28,393
  • 13
  • 77
  • 72

0 Answers0