[英]EmberJS - register precompiled handlebars template
對於我的EmberJS應用程序,我預先編譯了所有的把手模板,因此它們被加載為直接的Javascript文件。
問題是這些預編譯的模板沒有像我認為的那樣進入Ember容器 - 當我為視圖指定模板時,我收到以下錯誤。
Uncaught Error: assertion failed: You specified the templateName "application" for <MyApp.ApplicationView:ember164>, but it did not exist.
這是我的觀看代碼。
window.MyApp.ApplicationView = Ember.View.extend({
templateName: 'application'
});
我逐步完成執行,發現Ember容器中不存在視圖。 使用容器注冊預編譯模板時,我需要做些什么特別的事情嗎? 如果是這樣,怎么樣?
編輯:我一直在使用把手npm包編譯模板。
模板在Ember.TEMPLATES
上Ember.TEMPLATES
(這只是一個以模板名稱為鍵的哈希)
因此,當您的示例ApplicationView
被執行時,它將在Ember.TEMPLATES['application']
查找模板
雖然npm把手編譯器確實正確地編譯它們,但你仍然需要用Ember注冊它們才能正確加載它們。 您可以執行以下操作之一:
如果您更喜歡基於Ruby / Guard的解決方案,請查看我的要點: https : //gist.github.com/perlun/5286391
從你的Guardfile中使用它:
guard 'ember_handlebars',
:input => 'app/handlebars_templates',
:output => 'app/handlebars_compiled',
:remove_prefix => 'app/handlebars_templates/' do
watch(%r{app/handlebars_templates/(.+\.handlebars)})
end
```
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.