按照模板上的 Ember 指南,我执行以下操作:
App.PostsView = Ember.View.extend({
template: Ember.Handlebars.compile('I am the template')
});
但什么也没有呈现。当我使用templateName
风景is呈现:
// html
<script type='text/x-handlebars' data-template-name='posts-template'>
<h1>I am the template</h1>
</script>
// js
App.PostsView = Ember.View.extend({
templateName: 'posts-template'
});
我怎样才能使用模板来工作template
功能如指南中所述?
edit:
我确实遇到过这些:
emberjs 模板编译在 rc1 中不起作用
如何在 ember.js RC1 中指定使用带有已编译把手的视图
So this might看起来像重复的。然而,这首先似乎使用了 Ember 指南中未指定的一些额外工作,第二个是我正在做的事情,但它不起作用。
好的,这有效:
Ember.TEMPLATES['posts-template'] = Ember.Handlebars.compile('I am the template');
App.PostsView = Ember.View.extend({
templateName: 'posts-template'
});
我们发生的事情是我们的预编译模板被添加到Handlebars.templates
并不是Ember.TEMPLATES
事实上,我们正在使用它返回已编译的模板,例如:
App.PostsView = Ember.View.extend({
template: Handlebars.templates['posts-template']
});
所以看来人们应该避免干涉template
功能而是always使用templateName
它将在中寻找该名称Ember.TEMPLATES
.
希望这可以帮助某人节省一些时间:)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)