I want to store the innerHTML of an active menu item to display it as a title for my page. The title HTML is {{pageTitle}}, in the "container" template.
here is my (cleaned) HTML
<template name="container">
{{pageTitle}
{{ > SideMenu}}
</template>
<template name="SideMenu">
<ul id="menu-items" class="nav nav-stacked nav-pills">
<li id="menu-item-simple" class="">
<a href="#">
menuItem1
</a>
</li>
<li id="menu-item-simple" class="">
<a href="#">
menuItem2
</a>
</li>
</ul>
</template>
I created an helper to return the string
Template.container.helpers({
"pageTitle":function(){
return Session.get("pageTitle");
}
});
And an event to set the string to its correct value when a menu item is clicked
Template.SideMenu.events({
"click #menu-items":function(e,t){
var activeItem = $(this).find("li.active")
Session.set ("pageTitle",activeItem.children("a").innerHTML);
console.log (activeItem.children("a").innerHTML);
}
});
The console returns "undefined". I don't get what I am doing wrong and since I'm just beginning, I also wanted to know if I'm going the right way.
Aucun commentaire:
Enregistrer un commentaire