ember.js - 当我们在 Ember 中将一个 Action 传递给它时,yield 的行为如何?

标签 ember.js handlebars.js handlebarshelper

我有以下代码:

组件模板

{{#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/

相关文章:

javascript - Ember.js 中带有普通 anchor 标记的动态 linkTo

javascript - Ember js 从 Controller 获得 this.get() 请求的回调?

templates - Uncaught Error : Template was precompiled with an older version of Handlebars

javascript - meteor 模板中的简单数据反射

javascript - 在 ember/handlebars 中使用 value 和 valueBinding 有什么区别?

javascript - 如何映射此 Json 以与 Handlebars js 一起使用?

c# - Ember.js 查找从 webapi Controller 返回的第一个数据属性的模型

ember.js - Sinon 模拟对象不包含顶层原始对象的函数

templates - Handlebars If-Else If-Else 与字符串相等函数

node.js - 如何在 Handlebars View 中连接字符串