简体   繁体   English

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

[英]How do I expose a component via block params in Ember 1.10 + HTMLBars

With block params, I thought the following would work to expose a component to a nested control without need of the _yield hack. 使用块参数,我认为以下方法可以将组件暴露给嵌套控件,而不需要_yield hack。

{{#my-component as |myparam|}}
    {{log myparam}}
{{/my-component}}

This does not appear to work, as this log returns undefined. 这似乎不起作用,因为此日志返回undefined。

I'm using ember-cli 0.1.15 ember 1.10.0 and ember-cli-htmlbars 0.7.4 . 我正在使用ember-cli 0.1.15 ember 1.10.0ember-cli-htmlbars 0.7.4 Is there something I need to do to enable block params, or is this not the correct notation? 我需要做些什么来启用块参数,还是这不是正确的符号?

UPDATE UPDATE

For an example usage, consider a flexible carousel with slides and control buttons. 有关示例用法,请考虑使用带有滑动和控制按钮的灵活旋转木马。

{{#carousel-component as |carousel|}}
    {{#slide-component}}
      <button {{action "nextSlide" target=carousel}}>Next</button>
    {{/slide}}
{{/carousel-component}}

And to be specific, this is an attempt at solving this use case strictly using the new block params syntax available in Ember 1.10. 具体而言,这是尝试使用Ember 1.10中提供的新block params语法严格解决此用例。

Per http://emberjs.com/blog/2015/02/07/ember-1-10-0-released.html , it looks like the new syntax needs block params passed via the component's yield helper. 根据http://emberjs.com/blog/2015/02/07/ember-1-10-0-released.html ,看起来新语法需要通过组件的yield helper传递的块参数。 I've made a JSBin to illustrate: 我做了一个JSBin来说明:

http://emberjs.jsbin.com/jacosewefu/4/edit http://emberjs.jsbin.com/jacosewefu/4/edit

Passing the entire component as a block-param goes the principle of isolation, so unless there is an exceptional reason, pass specific arguments instead. 将整个组件作为块参数传递是隔离原则,因此除非有特殊原因,否则请传递特定参数。

Use this as template for your component: 将其用作组件的模板:

{{yield context}}

Then, as you write: 然后,当你写:

{{#carousel-component as |carousel|}}
    {{#slide-component}}
      <button {{action "nextSlide" target=carousel}}>Next</button>
    {{/slide}}
{{/carousel-component}}

More on block params: 更多关于块参数:
http://emberjs.com/blog/2015/02/07/ember-1-10-0-released.html#toc_block-params http://emberjs.com/blog/2015/02/07/ember-1-10-0-released.html#toc_block-params

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM