繁体   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