【问题标题】:How to use {{Yield}} helper with hash helper in ember js?如何在 ember js 中使用 {{Yield}} 助手和哈希助手?
【发布时间】:2019-03-20 23:24:45
【问题描述】:

有人可以用一个例子来解释一下在 emberjs 中与组件一起使用时使用 hash 的 yield helper 吗?

【问题讨论】:

    标签: ember.js ember-components


    【解决方案1】:

    在您的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}}
    

    希望对你有帮助!

    【讨论】:

    • 如何用上面的 foo 组件传递数据?
    • @Craicerjack 我通常这样做:``` {{ x.foo data=somedataref }} ```
    • 对不起,我的意思是在 hash foo 组件中,但它很酷,想通了
    【解决方案2】:

    Link 在 ember 组件中使用带有 yield 的哈希助手。

    Yield 用于share data within your component with the content it is wrapping,仅用于组件的块形式。

    哈希助手用于创建object。哈希助手是一个通用的对象构建器,给定哈希参数。

    【讨论】:

      【解决方案3】:

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

      【讨论】:

      • 答案中的一个例子比链接到一个更好:)
      • 完全正确,但我认为这根本不是一个有效的问题,Ember Guides 会保持最新。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-07-06
      • 2015-06-09
      • 1970-01-01
      • 2015-02-18
      相关资源
      最近更新 更多