2013-05-08 120 views
0

我試圖呈現一個視圖動態地Ember.js灰燼無法找到模板

Resume.ItemView = Em.View.create({ 
    click: function(){ 
    var view = Em.View.create({ 
     templateName: 'my_exp'}); 
    view.append(); 
    }, 
}); 

我在/模板my_exp.hbs

,但得到

Uncaught Error: assertion failed: You specified the templateName my_exp for <Ember.View:ember261>, but it did not exist. 

有試圖做到這一點的更好方法?誰能建議資源?

+0

如果你到控制檯,輸入'Ember.TEMPLATES',你看到你的模板集合中? – MilkyWayJoe 2013-05-08 22:45:08

+0

是: Ember.TEMPLATES; 對象{application:function,... my_exp:function ...} – 2013-05-08 22:49:04

+1

我的朋友...工作。謝謝 – 2013-05-09 02:40:18

回答

3

最近對Ember的更新刪除了defaultContainer以查找模板。 對於手動創建視圖的人來說,這造成了一些問題。

要達到您想要的效果,您需要使用createChildView

Resume.ItemView = Em.View.create({ 
    click: function(){ 
    var view = this.createChildView(Ember.View, { 
     templateName: 'my_exp' 
    }); 
    view.append(); 
    }, 
}); 

(見fiddle

+0

感謝您的回覆。現在我得到 未捕獲的錯誤:斷言失敗:您必須通過視圖的實例或子類 – 2013-05-09 02:34:47

+0

哎呀,現在修復了,您需要傳遞一個視圖類來實例化 – 2013-05-09 03:31:35