EmberJS - 检查模板是否存在
EmberJS - check if template exists
如何检查 Ember 路由对象中是否存在模板?
我需要在路线中检查这个;如果它不存在,我将为该路由呈现一个默认模板。
非常感谢!
如果您正在创建模板 运行 时间,请检查模板如下:
if (Ember.TEMPLATES["index"] == null) {
Ember.TEMPLATES["index"] = Ember.Handlebars.compile(content);
}
this.render('index', {
into: 'application'
});
要获取模板,您可以使用 Ember.getOwner(this).lookup("template:foo")
,其中 foo
是模板的名称。如果 returns 为 null,则模板不存在:
if (Ember.getOwner(this).lookup("template:foo")) {
// render template foo
} else {
// render default template
}
如何检查 Ember 路由对象中是否存在模板?
我需要在路线中检查这个;如果它不存在,我将为该路由呈现一个默认模板。
非常感谢!
如果您正在创建模板 运行 时间,请检查模板如下:
if (Ember.TEMPLATES["index"] == null) {
Ember.TEMPLATES["index"] = Ember.Handlebars.compile(content);
}
this.render('index', {
into: 'application'
});
要获取模板,您可以使用 Ember.getOwner(this).lookup("template:foo")
,其中 foo
是模板的名称。如果 returns 为 null,则模板不存在:
if (Ember.getOwner(this).lookup("template:foo")) {
// render template foo
} else {
// render default template
}