[英]Ember: How to use link-to inside a component
I have a component that contains a link-to. 我有一个包含链接的组件。 The component is more complicated, but for simplicity here: 该组件更加复杂,但是为了简单起见,在这里:
//Component.hbs
{{#link-to link model}}{{yield}}{{/link-to}}
The problem is sometimes I will pass a model, sometimes I will not. 问题是有时我会通过模型,有时我不会。
//Route.hbs
//providing the model
{{my-component link='chosenroute' model='chosenmodel'}}
//omitting a model - doesn't work
{{my-component link='otherroute'}}
How do I make the model argument optional? 如何使模型参数可选?
Just put an if/else. 只需添加一个if / else。 undefined
is not a good parameter for link-to. undefined
不是链接的好参数。
//Component.hbs //Component.hbs
{{#if model}}
{{#link-to link model}}{{yield}}{{/link-to}}
{{else}}
{{#link-to link}}{{yield}}{{/link-to}}
{{/if}}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.