从Handlebars传递数据给Ember JS [英] Passing data to Ember JS from Handlebars
问题描述
我有一个菜单栏,其状态/颜色等点击时发生变化。这些属于不同的JSP / HTML页面。当我点击页面时,有一个句柄#bindAttr决定每个标签式菜单项的类。例如
< li id =index{{#bindAttr class =active}}>
< a href =./ index.jsp>
< i class =icon-dashboard>< / i>
< span>仪表板< / span>
< / a>
< / li>
我在这里需要的也是传递别的东西,以便计算出来的属性可以根据location.href这个类是否应该为true。有没有办法将li标记的id传递给计算属性active?解决方案
解决方案。 Custom HandleBar Helper Function
< li {{activetabindex.jsp}}>
Handlebars.registerHelper(activetab,function(tabname){
var currentPage = window.location.href; console.log(currentPage); if(currentPage.indexOf(tabname)! = -1){
returnclass = active;
}
else {
return;
}
});
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"
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 "";
}
});
这篇关于从Handlebars传递数据给Ember JS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!