I'm using Twitter Bootstrap for navigation in my Ember.js app. Bootstrap uses an active
class on the li
tag that wraps navigation links, rather than setting the active
class on the link itself.
Ember.js's new linkTo
helper will set an active
class on the link but (as far as I can see) doesn't offer any to hook on to that property.
Right now, I'm using this ugly approach:
{{#linkTo "inbox" tagName="li"}}
<a {{bindAttr href="view.href"}}>Inbox</a>
{{/linkTo}}
This will output:
<li class="active" href="/inbox"><a href="/inbox">Inbox</a></li>
Which is what I want, but is not valid HTML.
I also tried binding to the generated LinkView's active
property from the parent view, but if you do that, the parent view will be rendered twice before it is inserted which triggers an error.
Apart from manually recreating the logic used internally by the linkTo
helper to assign the active
class to the link, is there a better way to achieve this effect?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…