Ember.js 如何通过Ember 1.10+;中的块参数公开组件;HTMLBars

Ember.js 如何通过Ember 1.10+;中的块参数公开组件;HTMLBars,ember.js,htmlbars,Ember.js,Htmlbars,对于block参数,我认为下面的方法可以将组件暴露到嵌套控件中,而不需要\u yieldhack {{#my-component as |myparam|}} {{log myparam}} {{/my-component}} 这似乎不起作用,因为此日志返回undefined 我正在使用ember-cli 0.1.15ember-1.10.0和ember-cli-htmlbar 0.7.4。是否需要执行某些操作来启用块参数,或者这不是正确的表示法 更新 对于一个示例用法,考虑一个带幻灯

对于block参数,我认为下面的方法可以将组件暴露到嵌套控件中,而不需要
\u yield
hack

{{#my-component as |myparam|}}
    {{log myparam}}
{{/my-component}}
这似乎不起作用,因为此日志返回undefined

我正在使用
ember-cli 0.1.15
ember-1.10.0
ember-cli-htmlbar 0.7.4
。是否需要执行某些操作来启用块参数,或者这不是正确的表示法

更新

对于一个示例用法,考虑一个带幻灯片和控制按钮的灵活旋转木马。

{{#carousel-component as |carousel|}}
    {{#slide-component}}
      <button {{action "nextSlide" target=carousel}}>Next</button>
    {{/slide}}
{{/carousel-component}}
{{{#旋转木马组件为|旋转木马}
{{{#滑动组件}
下一个
{{/幻灯片}
{{/carousel组件}
具体来说,这是严格使用Ember 1.10中提供的新
块参数
语法解决此用例的尝试。

根据,新语法似乎需要通过组件的
yield
助手传递块参数。我制作了一个JSBin来说明:


将整个组件作为块参数传递符合隔离原则,因此除非有特殊原因,否则应传递特定参数。

将此用作组件的模板:

{{yield context}}
然后,正如你所写:

{{#carousel-component as |carousel|}}
    {{#slide-component}}
      <button {{action "nextSlide" target=carousel}}>Next</button>
    {{/slide}}
{{/carousel-component}}
{{{#旋转木马组件为|旋转木马}
{{{#滑动组件}
下一个
{{/幻灯片}
{{/carousel组件}
有关块参数的详细信息:

@runspired更新了我的答案,看起来
{yield}
需要变成
{{yield controller}
:-)