2013-03-29 75 views
1

我目前呈現的視圖列表:渲染多個視圖/控制器雙

<ul> 
    {{#each newsItem in controller}} 
     {{view App.NewsItemView contentBinding="newsItem" class="news-item" }} 
    {{/each}} 
    </ul> 

但我想注入NewsItemController到每個視圖。

我使用render嘗試過,但這個似乎只支持單一視圖,給予例外:

Uncaught Error: Handlebars error: Could not find property 'control' on object .

我發現使用control,而不是簡單地提到,但是這似乎不再被包括在內。

那麼如何渲染同一視圖的多個版本,在每個視圖中注入一個單獨的控制器?

回答

1

{{render}}應該在當前的主版本(如果您從Github構建它)中修復。您應該能夠多次使用它,如果你通過一個模型:

<ul> 
{{#each controller}} 
    {{render "newsItem" this}} 
{{/each}} 
</ul> 

{{control}}仍然存在,只是隱藏在背後的旗(因爲它仍處於試驗階段)。要使用它,您需要在包括ember.js文件之前執行:ENV.EXPERIMENTAL_CONTROL_HELPER = true。如果你可以避免使用它,那會更好。

但是我認爲最簡單的方法是使用itemController

<ul> 
    {{#each controller itemController="newsItem"}} 
    {{view App.NewsItemView class="news-item" }} 
    {{/each}} 
</ul> 

我認爲你可以將它們結合起來,使其更簡單(我還沒有嘗試過):

<ul> 
    {{each controller itemController="newsItem" itemViewClass="App.NewsItemView"}} 
</ul>