2017-06-13 85 views
1

我有以下代码:当我们在Ember中传递动作时,yield如何表现?

组件模板

{{#link-to "user.profile" account.id disabled=user.online}} 
    {{yield}} 
{{/link-to}} 

模板

{{#my-component data=x}} 
    <button> MY BUTTON </button> 
{{/my-component}} 

我使用的组件在不同的模板,我想将产生的元素有一种行为。我读过你可以像这样使用它,但我无法真正掌握这一行为。

{{#link-to "user.profile" account.id disabled=user.online}} 
    {{yield (action "showModal")}} 
{{/link-to}} 

任何人都可以揭示出这个问题的一些轻?

回答

1

这里它的用法:

{{#my-component as |act|}} 
    <button onclick={{action act}}>Button</button> 
{{/my-component}} 

Here是工作玩弄。

要了解更多:这里是一个good blog post。这是作者关于上下文组件的三个帖子之一。

相关问题