coffeescript - #each with call to helper ignores first entry in array -


i'm trying generate menu handlebars, based on array (from coffeescript):

template.moduleheader.modules = -> [     { "modulename": "dashboard", "linkname": "dashboard" }     { "modulename": "roommanager", "linkname": "raumverwaltung" }     { "modulename": "usermanager", "linkname": "benutzerverwaltung" } ] 

the iteration looks (from html code):

{{#each modules}} <li {{this.isactive this.modulename}}>     <a class="{{this.modulename}}" href="#">{{this.linkname}}</a> </li> {{/each}} 

{{this.isactive}} defined (coffeescript code again):

template.moduleheader.isactive = (currentmodulename) ->     if currentmodulename session.get 'module'         "class=active" 

based on session.get 'module' appropriate menu item highlighted css class active.

on reload, session-variable module contains 'dashboard', first entry in array, however, not active-class. if add empty object first item modules-array, 'dashboard'-item highlighted.

the strange thing is, first item (dashboard) rendered fine, not have active-class, raises impression, function this.isactive not called first item.

am doing wrong?

really going out on whim here traditional approach below. don't know whether work big comment, yet again it's not guaranteed fix. let me know how goes:

replace html with

{{#each modules}} <li {{isactive}}>     <a class="{{modulename}}" href="#">{{linkname}}</a> </li> {{/each}} 

replace cs with

template.moduleheader.isactive = () ->     currentmodule =     currentmodulename = currentmodule.modulename     if currentmodulename session.get 'module'         "class=active" 

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -