如何在ember js中将{{Yield}}帮助程序与哈希帮助程序一起使用?

时间:2018-10-16 12:16:11

标签: ember.js ember-components

有人可以举例说明在emberjs中使用组件时使用的带有哈希的yield helper吗?

3 个答案:

答案 0 :(得分:1)

Ember Guides中讨论了使用{{yield}},包括一个小示例。您可以在tutorial application中找到另一个更详细的示例,该示例是《 Ember Guides》的一部分。

答案 1 :(得分:1)

Link,将余热助手与ember组件中的yield结合使用。

Yield用于 share data within your component with the content it is wrapping ,并且仅以组件形式使用。

哈希助手用于创建object。哈希帮助程序是给定哈希参数的对象的通用生成器。

答案 2 :(得分:0)

在您的yield中实施template.hbs

{{yield (hash
  foo=(component "path/to/component/foo")
  bar=(component "path/to/component/bar")
)}}

您可以像这样实例化它:

{{#baz
  as |x|
}}
  {{x.foo}}
  {{x.bar}}
{{/baz}}

希望有帮助!