Reputation: 15303
I am using Handlebars.js template to make main and subnavi links, i am getting main step of the links, but the sublink not getting, still i am getting double step links properly on first links without proper text and link info.
my template :
<script id="navi-template" type="text/x-handlebars-template">
{{#each links}}
{{#if subLinks}}
<li>
<a href="{{link}}">{{label}}</a>
<ul>
{{#each subLinks}}
<a href="{{link}}">{{label}}</a>
{{/each}}
</ul>
</li>
{{else}}
<li><a href="{{link}}">{{label}}</a></li>
{{/if}}
{{/each}}
</script>
I updated my data and jquery what i am using in jsfiffle: click to visit fiddle
thanks in advance..
Upvotes: 1
Views: 119
Reputation: 3709
I am sure the {{#each}}
construction requires you to use {{this}}
{{#each subLinks}}
<a href="{{link}}">{{this}}</a>
{{/each}}
Think of it as how i
(or any other counter) is used in for
cycles.
If you iterate over objects you can do stuff like
{{#each object}}
{{this.name}} : {{this.content}}
{{/each}}
While your object is
var Example = {
name: "Object",
content: "example"
}
Upvotes: 1