问题描述
我有一个列表,我想自动将一个项目设置为 class="active".鉴于以下引导程序代码:
I have a list and I'd like to set one item as class="active" automatically. Given the following bootstrap code:
<ul class="nav">
<li {{bindAttr class="atIndex:active"}}>{{#linkTo "index"}}Index{{/linkTo}}</li>
<li {{bindAttr class="atAbout:active"}}>{{#linkTo "about"}}About{{/linkTo}}</li>
<li {{bindAttr class="atLogin:active"}}>{{#linkTo "login"}}Login{{/linkTo}}</li>
</ul>
atIndex、atAbout 和 atLogin 驻留在我的 ApplicationController 中.
atIndex, atAbout and atLogin reside in my ApplicationController.
渲染为:
<ul class="nav">
<li class="active"><a...>Index{{/linkTo}}</li>
<li><a...>About<a></li>
<li><a...>Login<a></li>
</ul>
使用 Ember 1.0 pre4 执行此操作的最佳方法是什么?我宁愿不为每个视图或控制器添加特殊代码.
What's the best way to do this with Ember 1.0 pre4? I'd rather not add special code to every view or controller.
PS - atIndex: true
有效,但 atIndex: function() {return true;}.property().volatile()
没有.这让我觉得我做错了什么.
PS - atIndex: true
works, but atIndex: function() {return true; }.property().volatile()
does not. Which makes me think I'm doing something wrong.
谢谢!
推荐答案
{{#link-to "dashboard" tagName="li" href=false}}
<a {{bind-attr href="view.href"}}>
Dashboard
</a>
{{/link-to}}
这篇关于将“活动"类分配给 EmberJS 中的选定列表项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!