![](/img/trans.png)
[英]How can I update ember-i18n component to work in ember 1.10 with HTMLbars?
[英]How do I expose a component via block params in Ember 1.10 + HTMLBars
使用塊參數,我認為以下方法可以將組件暴露給嵌套控件,而不需要_yield
hack。
{{#my-component as |myparam|}}
{{log myparam}}
{{/my-component}}
這似乎不起作用,因為此日志返回undefined。
我正在使用ember-cli 0.1.15
ember 1.10.0
和ember-cli-htmlbars 0.7.4
。 我需要做些什么來啟用塊參數,還是這不是正確的符號?
UPDATE
有關示例用法,請考慮使用帶有滑動和控制按鈕的靈活旋轉木馬。
{{#carousel-component as |carousel|}}
{{#slide-component}}
<button {{action "nextSlide" target=carousel}}>Next</button>
{{/slide}}
{{/carousel-component}}
具體而言,這是嘗試使用Ember 1.10中提供的新block params
語法嚴格解決此用例。
根據http://emberjs.com/blog/2015/02/07/ember-1-10-0-released.html ,看起來新語法需要通過組件的yield
helper傳遞的塊參數。 我做了一個JSBin來說明:
將整個組件作為塊參數傳遞是隔離原則,因此除非有特殊原因,否則請傳遞特定參數。
將其用作組件的模板:
{{yield context}}
然后,當你寫:
{{#carousel-component as |carousel|}}
{{#slide-component}}
<button {{action "nextSlide" target=carousel}}>Next</button>
{{/slide}}
{{/carousel-component}}
更多關於塊參數:
http://emberjs.com/blog/2015/02/07/ember-1-10-0-released.html#toc_block-params
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.