2012-12-26 61 views
1

我在下面試圖做的是使用partials來使我的視圖更加模塊化。不幸的是,這是行不通的。如何將ember.js部分添加到模板?

我得到


Uncaught TypeError: Cannot read property 'view' of undefined in the (compiled) _dataForLeftPane.js @ the following line, 
    stack1 = foundHelper ? foundHelper.call(depth0, stack1, {hash:{}}) : helperMissing.call(depth0, "outlet", stack1, {hash:{}}); 

如果我刪除container.hjs聲明的泛音(請參見下面的代碼),並把各自的內容代替,一切正常。但是隻有當我介紹部分時,事情纔會停止。

file: app_router.js.coffee 

root: Ember.Route.extend(
    index: Ember.Route.extend(
    route: '/' 
    connectOutlets: (router) -> 
     router.get('applicationController').connectOutlet('container') 
     router.get('containerController').connectOutlet('dataForLeftPane', 'dataForLeftPane', [{login:'wycats'},{login:'tomdale'}]) 
     router.get('containerController').connectOutlet('dataForRightPane', 'dataForRightPane', [{id:'1234'},{id:'qwerty'}]) 
) 
) 
file: views/application_view.js.coffee 

App.ApplicationView = Ember.View.extend(
    templateName: 'application' 
) 

App.ContainerView = Ember.View.extend(
    templateName: 'a/container' 
) 

App.DataForLeftPaneView = Ember.View.extend(
    templateName: 'a/dataForLeftPane' 
) 

App.DataForRightPaneView = Ember.View.extend(
    templateName: 'a/dataForRightPane' 
) 
file: templates/a/container.hjs 

{{> _a_leftPane}} 
{{> _a_rightPane}} 
file: templates/a/_leftPane.hbs 

{{outlet dataForLeftPane}} 
file: templates/a/_rightPane.hbs 

{{outlet dataForRightPane}} 
file: templates/a/dataForRightPane.hjs 

{{#each person in controller}} 
    {{person.id}} 
{{/each}} 
file: templates/a/dataForLeftPane.hjs 

{{#each person in controller}} 
    {{person.name}} 
{{/each}} 

回答

0

你可以 '呼叫' 與另一模板中的view helper視圖。

file: templates/parentView.hjs 
{{view.someProperty}} 
//here is the parent view calling a template 
{{view "App.templateView" contentBinding="view.content"}} 

這將插入指定的App.templateView與內容綁定到渲染視圖的傳遞內容屬性。您可以將所需的任何內容作爲templateViews內容傳遞。

這很可能是你想要做的,但我不確定是否正確地讀你的問題。

另外,這在語義上接近於使用傳遞的本地渲染局部軌道。所以我認爲這可能是您所尋找的解決方案,因爲您指的是「部分」。