خرید بک لینک

Vote count: 0

I have an array of objects like this:

[
  {
   "id": 2,
   "title": "LA COPA",
   "parent_menu_id": null
  },
  {
   "id": 3,
   "title": "CALENDARIO",
   "parent_menu_id": null
  },
  {
   "id": 5,
   "title": "Toeo",
   "parent_menu_id": 2
  },
  {
   "id": 6,
   "title": "Nice",
   "parent_menu_id": 2
  }
]

This is the structure of a menu. The key "parent_menu_id" means that item id: 5 is child of item id:2.

This is the desired output:

[
  {
   "id": 2,
   "title": "LA COPA",
   "active": true,
   "parent_menu_id": null,
   "submenus":[
     {
       "id": 5,
       "title": "Toeo",
       "active": true,
       "parent_menu_id": 2
     },
     {
       "id": 6,
       "title": "Nice",
       "parent_menu_id": 2
     }
   ]
  },
  {
   "id": 3,
   "title": "CALENDARIO",
   "active": true,
   "parent_menu_id": null
  }
]

I know the algorithm:

  1. if pareny_menu_id is different than null search the key id == parent_menu_id.
asked 23 secs ago

- - , .
.

برچسب: نویسنده: استخدام کار تاريخ: چهارشنبه 23 تير 1395 ساعت: 1:52

صفحه بندی