This is my object and I want to create a menu from the submenu in it.
I am working on a project that needs to categorize the menu list groups by their parent name.
[
{
"parent": "Assessment",
"name": "Assessment Due date"
},
{
"parent": "Assessment",
"name": "Grading Schemes"
},
{
"parent": "Registration",
"name": "Manual Grouping"
}
]
I have tried the Javascript code below
jQuery(document).ready(function ($) {
$(document).on('change','#parentMenu', function () {
console.log("It has changed");
var ParentMenuId = $(this).val();
// console.log(ParentMenuId);
$.ajax({
type:'get',
url: '{!! URL::route('submenu') !!}',
data: { 'id': ParentMenuId },
dataType:'json',
success: function (data) {
$("#submenulist").empty();
data.forEach(function (element) {
$("#submenulist").append('<li><a href="#">'+ element.name +'</a></li>');
})
}
});
});
});
I am getting the list of the items like this
<li>Assessment Due date</li>
<li>Grading Schemes<li>
<li>Manual Grouping<li>
but I want to group it by the parent so I want to produce this
<ul>Assessment<\ul>
<li>-Assessment Due date</li>
<li>-Grading Schemes</li>
<ul>Registration</ul>
<li>-Manual Grouping</li>
Please, any one to assist me get the menu in the form of parent and children.
` is supposed to **wrap** the `- `s, not precede them. e.g. `
– Erich Oct 02 '19 at 02:15- item1
- item 2
`