【发布时间】:2019-03-20 23:24:45
【问题描述】:
有人可以用一个例子来解释一下在 emberjs 中与组件一起使用时使用 hash 的 yield helper 吗?
【问题讨论】:
有人可以用一个例子来解释一下在 emberjs 中与组件一起使用时使用 hash 的 yield helper 吗?
【问题讨论】:
在您的template.hbs 中实现yield:
{{yield (hash
foo=(component "path/to/component/foo")
bar=(component "path/to/component/bar")
)}}
你可以这样实例化它:
{{#baz
as |x|
}}
{{x.foo}}
{{x.bar}}
{{/baz}}
希望对你有帮助!
【讨论】:
Link 在 ember 组件中使用带有 yield 的哈希助手。
Yield 用于share data within your component with the content it is wrapping,仅用于组件的块形式。
哈希助手用于创建object。哈希助手是一个通用的对象构建器,给定哈希参数。
【讨论】:
Ember Guides 中讨论了使用{{yield}},包括一个小示例。您可以在 tutorial application 中找到另一个更详细的示例,它是 Ember 指南的一部分。
【讨论】: