我想知道如何将完整的块传递给我的组件。 我已经找到了https://guides.emberjs.com/v2.9.0/components/block-params/ 但我不明白为什么会有
//my-component.hbs
{{#if hasBlock}}
{{yield post.title}}
{{yield post.body}}
{{yield post.author}} ...
为什么我必须说出我想要的东西?这没有任何意义,因为无论我在那里做什么,我都希望得到(显示)我传递给组件的整个块。
所以我只尝试使用yield:
//my-component.hbs
{{#if hasBlock}}
{{yield}} ...
以这种方式使用组件:
//myroute.hbs
{{#my-component car=model}}
{{car.name}} - {{car.color}}
{{/my-component}}
这不起作用,但我预计'car.name - car.color'将在组件的{{yield}}中呈现......
有人可以解释一下吗,请问?
答案 0 :(得分:0)
我承认,这有点令人困惑。发生的事情是组件正在产生(返回)您可以在块中使用的值。尝试这样的事情:
{{#my-component car=model as |car|}}
{{car.name}} - {{car.color}}
{{/my-component}}
然后在你的组件中:
{{#if hasBlock}}
{{yield car}}
{{else}}
default no-block template goes here...
{{/if}}