I am hoping to get some advice. Basically I have menu items stored in an array, any item may have it's own sub menu items. I am trying to figure out how I can keep track of which menu (array) a user is currently scrolling through. The end goal would be a user using keys on the keyboard can go from item to item and if it has a sub menu they could access those items if they chose. The following code is how my menu items are stored. I appreciate any advice, thank you!
var menu = [{
"title": "Home",
"link": "/index.jsp"
}, {
"title": "Our Company",
"link": "javascript:;",
"subMenu": [{
"title": "Employees",
"link": "/employees"
}, {
"title": "Investors →",
"link": "/invest",
"subMenu": [{
"title": "News",
"link": "/invest/news"
}, {
"title": "History",
"link": "/invest/history"
}]
}, {
"title": "xyz",
"link": "/xyz"
}, {
"title": "xyz",
"link": "/xyz"
}, {
"title": "xyz",
"link": "/xyz"
}, {
"title": "xyz",
"link": "/xyz/"
}]
}, {
"title": "Human Resources",
"link": "javascript:;",
"subMenu": [{
"title": "Apply",
"link": "/apply"
}, {
"title": "Information",
"link": "/info"
}, {
"title": "Complaints",
"link": "/complains"
}]
}];
As of right now I just have a variable with a number that I increase / decrease when pressing keys on the board. I know I can check to see if subMenu exists for any item when they access it, I'm just having trouble wrapping my head around keeping track of the parent item when accessing sub menus, etc.
Should I be thinking instead about using another array to keep track of the menu items the user is currently on? and pushing / popping them out of there as they navigate through?