如何使用新的Ember路由器绑定到链接的活动类?

编程入门 行业动态 更新时间:2024-10-24 20:16:49
本文介绍了如何使用新的Ember路由器绑定到链接的活动类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我在我的Ember.js应用程序中使用Twitter Bootstrap导航。 Bootstrap在包含导航链接的 li 标签上使用活动 c>类,而不是设置

Ember.js的新的 linkTo 帮助器将设置链接上的活动类,但(尽可能看到)不提供任何挂钩到该属性。

现在,我使用这个丑陋的方法:

{{linkToinboxtagName = li}} < a {{bindAttr href =view.href}}>收件箱< / a> {{/ linkTo}}

这将输出:

< li class =activehref =/ inbox>< a href =/ inbox> Inbox< / a>< ; /立GT;

我想要什么,但HTML无效。

我还尝试从父视图绑定到生成的LinkView的活动属性,但是如果这样做,父视图将在它之前呈现两次插入它会触发错误。

除了手动重新创建由 linkTo 帮助者内部使用的逻辑, code> active 类链接,有没有更好的方法来实现这个效果?

解决方案

您还可以使用嵌套的链接到:

{{link-toccprPracticeSession.infocontroller.controllers .ccprPatient.content content tagName ='li'href = false eventName ='dummy'}} {{#link-toccprPracticeSession.infocontroller.controllers.ccprPatient.content content}} Info {{/ link -to}} {{/ link-to}}

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?

解决方案

You can also use nested link-to's:

{{#link-to "ccprPracticeSession.info" controller.controllers.ccprPatient.content content tagName='li' href=false eventName='dummy'}} {{#link-to "ccprPracticeSession.info" controller.controllers.ccprPatient.content content}}Info{{/link-to}} {{/link-to}}

更多推荐

如何使用新的Ember路由器绑定到链接的活动类?

本文发布于:2023-11-25 22:34:41,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1631621.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:绑定   如何使用   路由器   链接   Ember

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!