我有以下代码:
组件模板
{{#link-to "user.profile" account.id disabled=user.online}}
{{yield}}
{{/link-to}}
模板
{{#my-component data=x}}
<button> MY BUTTON </button>
{{/my-component}}
我在不同的模板中使用该组件,我希望生成的元素有一个 Action 。我读过你可以像这样使用它,但我无法真正理解这种行为。
{{#link-to "user.profile" account.id disabled=user.online}}
{{yield (action "showModal")}}
{{/link-to}}
任何人都可以阐明这个主题吗?
最佳答案
这里是它的用法:
{{#my-component as |act|}}
<button onclick={{action act}}>Button</button>
{{/my-component}}
Here正在忙忙碌碌。
要了解更多:这里是一个good blog post .这是作者关于上下文组件的三篇文章之一。
关于ember.js - 当我们在 Ember 中将一个 Action 传递给它时,yield 的行为如何?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44525262/