EmberJS - 注册预编译的车把模板

Jar*_*les 6 javascript handlebars.js ember.js

对于我的EmberJS应用程序,我预先编译了所有的把手模板,因此它们被加载为直接的Javascript文件.

问题是这些预编译的模板没有像我认为的那样进入Ember容器 - 当我为视图指定模板时,我收到以下错误.

Uncaught Error: assertion failed: You specified the templateName "application" for <MyApp.ApplicationView:ember164>, but it did not exist. 
Run Code Online (Sandbox Code Playgroud)

这是我的观看代码.

window.MyApp.ApplicationView = Ember.View.extend({
   templateName: 'application'
});
Run Code Online (Sandbox Code Playgroud)

我完成了执行,发现Ember容器中不存在视图.使用容器注册预编译模板时,我需要做些什么特别的事情吗?如果是这样,怎么样?

编辑:我一直在使用把手npm包编译模板.

Jar*_*les 1

虽然 npm handlebars 编译器确实正确编译了它们,但您仍然需要向 Ember 注册它们才能正确加载它们。您可以执行以下操作之一:

  • 使用 Ember.TEMPLATES['sometemplate'] = COMPILED TEMPLATE 手动加载它们。这虽然有效,但会变得很痛苦。
  • 使用像 npm ember-precompile 这样的特殊编译器,它将以编译后的模板自动注册到 Ember 模板容器中的方式进行编译。