簡體   English   中英

EmberJS - 注冊預編譯的車把模板

[英]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.TEMPLATESEmber.TEMPLATES (這只是一個以模板名稱為鍵的哈希)

因此,當您的示例ApplicationView被執行時,它將在Ember.TEMPLATES['application']查找模板

雖然npm把手編譯器確實正確地編譯它們,但你仍然需要用Ember注冊它們才能正確加載它們。 您可以執行以下操作之一:

  • 用Ember.TEMPLATES ['sometemplate'] = COMPILED TEMPLATE手動加載它們。 這有效但卻變得很痛苦。
  • 使用像npm ember-precompile這樣的特殊編譯器,它將以這樣的方式編譯它們,使得編譯的模板自動在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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM