问题
I have a menu bar whose status/color etc changes when clicked. These belong to different JSP/HTML pages. When I click on the page, there is a handlebar #bindAttr which decides the class of the each tabbed menuitem. For e.g.
<li id="index" {{#bindAttr class="active"}}>
<a href="./index.jsp">
<i class="icon-dashboard"></i>
<span>Dashboard</span>
</a>
</li>
What I need here is also to pass something else so that the computed property can find out based on the location.href whether this class should be true. Is there any way to pass the id of the "li" tag to the computed property "active"
回答1:
Solved it. Custom HandleBar Helper Function
<li {{activetab "index.jsp"}}>
Handlebars.registerHelper("activetab", function(tabname) {
var currentPage = window.location.href; console.log(currentPage); if(currentPage.indexOf(tabname)!=-1){
return "class=active";
}
else{
return "";
}
});
来源:https://stackoverflow.com/questions/11355566/passing-data-to-ember-js-from-handlebars