[英]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.