Hi!
I’m struggling with how to approach creating a dynamic navigational menu.
Based on user permissions, only specific routes are made available to users. The data for the navigational menu will be handled by an API, but presently, I’ve just hard-coded an array in the app.js file with a child array for subItems. See the code below.
//app.js
import Ember from 'ember';
let navItems = [{
title: 'Dashboard',
url: 'app.dashboard',
subItems: [
{
title: 'Overview',
url: 'app.dashboard.overview'
}, {
title: 'Title',
url: 'app.dashboard.overview'
}
]
}, {
title: 'Conversations',
url: 'app.conversations'
}, {
title: 'Analytics',
url: 'app.analytics',
subItems: [
{
title: 'Overview',
url: 'app.dashboard.overview'
}, {
title: 'Title',
url: 'app.dashboard.overview'
}
]
}];
export default Ember.Route.extend({
model() {
return navItems;
}
});
I’ve added the model objects to the app.hbs file below. The parent navItems render, but none of the child navItems.subItems work. I get no errors.
<nav id="menu">
<ul>
{{#each model as |navItems|}}
<li>
<span>{{navItems.title}}</span>
{{#if navItems.subItems}}
<ul>
{{#each model as |navItems|}}
<li>
{{#link-to navItems.subItems.url}}
{{navItems.subItems.title}}
{{/link-to}}
</li>
{{/each}}
</ul>
{{/if}}
</li>
{{/each}}
</ul>
</nav>
I don’t know if I’ve formatted the model data or have configured app.js incorrectly. Any feedback would be greatly appreciated. Thanks