简体   繁体   English

ember:绑定属性在错误的标记上计算

[英]ember: bound attributes are evaluated on the wrong tag

I want to highlight a selected navigation element and so I have bound an attribute to the li of a navigation bar like this: 我想突出显示一个选定的导航元素,所以我将一个属性绑定到导航栏的li,如下所示:

<li {{bindAttr class="isHome:active"}}>{{#linkTo 'home'}}Home{{/linkTo}}</li>

The attribute is evaluated correctly and adds the right class - but not to the li, instead it gets added to the a which results in: 正确评估属性并添加正确的类 - 但不添加到li,而是将其添加到a,这导致:

<li class="" data-bindattr-1="1"><a id="ember237" class="ember-view active" href="#/home">Home</a></li> 

Is there something wrong here with the markup or is this a bug?! 这里的标记是否有问题,或者这是一个错误?!

There are two things happening here: 这里发生了两件事:

  1. The isHome property is not getting applied to your li isHome属性未应用于您的li
  2. The {{linkTo}} helper, coincidentally, adds an active class to links when the route it points to is active. 巧合的是, {{linkTo}}助手会在链接指向的路由active为其添加active类。

This is making you think that the active class is getting moved. 这让你觉得active类正在被移动。 You can try logging the isHome property (via {{log isHome}} ) to see whether it is true as you expect. 您可以尝试记录isHome属性(通过{{log isHome}} )以查看它是否符合您的预期。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM