Passing data to Ember JS from Handlebars

旧巷老猫 提交于 2019-12-11 06:46:25

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!