简体   繁体   English

灰烬如何将LinkView与视图助手一起使用?

[英]Ember how to use LinkView with view helper?

In Ember, I want to create a link with an optional class. 在Ember中,我想创建一个带有可选类的链接。 In the template, I should be able to define the binding, on which the optional class is set. 在模板中,我应该能够定义绑定,在该绑定上设置了可选类。 The target HTML should look like this 目标HTML应如下所示

<li class="completed"><a>Index</a></li> < completed
<li class="active"><a>Index</a></li> < active
<li class=""><a>Index</a></li> < in-active

So the active/in-active states can be achieved with the link-to helper; 因此,可以通过link-to帮助程序来获得活动/非活动状态;

{{#link-to "index" tagName="li"}}<a>Index</a>{{/link-to}}

However, this doesn't allow me to define the optional "complete" binding. 但是,这不允许我定义可选的“完整”绑定。 So I'm thinking about creating a subclass of LinkView , which does provide said binding. 因此,我正在考虑创建LinkView的子类,该子类确实提供了所述绑定。 So the next step would be to create said subclass, and implement the binding. 因此,下一步将是创建所述子类,并实现绑定。 However I don't feel like duplicating the link-to helper, and am fine with using the view helper. 但是,我不想复制link-to帮助器,并且可以很好地使用view帮助器。 However I cannot figure out how the view helper is supposed to work with LinkView : 但是我无法弄清楚view助手应该如何与LinkView一起LinkView

{{#view Ember.LinkView "index" }}Index{{/view}}

DEPRECATION: Global lookup of Ember.LinkView from a Handlebars template is deprecated. 弃用:不建议从Handlebars模板全局查找Ember.LinkView。
Uncaught TypeError: Cannot read property 'length' of undefined 未捕获的TypeError:无法读取未定义的属性“ length”

{{#view Ember.LinkView target="index" }}Index{{/view}}

DEPRECATION: Global lookup of Ember.LinkView from a Handlebars template is deprecated. 弃用:不建议从Handlebars模板全局查找Ember.LinkView。
Uncaught TypeError: Cannot read property 'length' of undefined 未捕获的TypeError:无法读取未定义的属性“ length”

I've been reading both the source of LinkView and link-to , but can't figure out how to proceed. 我一直在阅读LinkViewlink-to的源代码,但不知道如何进行。

您可以像这样使用类绑定

{{#link-to 'index' tagName='li' class="active:active completed:completed"}}<a href="#">Index</a>{{/link-to}}

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

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