Ember.js RC1-指定';模板&x27;
按照Ember模板指南,我将执行以下操作:Ember.js RC1-指定';模板&x27;,ember.js,Ember.js,按照Ember模板指南,我将执行以下操作: App.PostsView = Ember.View.extend({ template: Ember.Handlebars.compile('I am the template') }); 但什么都没有呈现。使用templateName时,将呈现视图: //html <script type='text/x-handlebars' data-template-name='posts-template'> <h1&g
App.PostsView = Ember.View.extend({
template: Ember.Handlebars.compile('I am the template')
});
但什么都没有呈现。使用templateName
时,将呈现视图:
//html
<script type='text/x-handlebars' data-template-name='posts-template'>
<h1>I am the template</h1>
</script>
如何使用指南中所述的模板
功能使模板正常工作
编辑:
我确实遇到了这些:
所以这看起来像是一个复制品。但是,第一个似乎使用了余烬指南中未指定的一些额外工作,第二个是我正在做的,但它不起作用。好的,这可以:
Ember.TEMPLATES['posts-template'] = Ember.Handlebars.compile('I am the template');
App.PostsView = Ember.View.extend({
templateName: 'posts-template'
});
我们的预编译的模板被添加到把手.模板
中,而不是余烬.模板
,以及我们使用此返回已编译模板的事实,例如:
App.PostsView = Ember.View.extend({
template: Handlebars.templates['posts-template']
});
因此,似乎应该避免干扰template
函数,而是始终使用templateName
,它将在Ember.TEMPLATES
中查找该名称
希望这有助于节省一些时间:)您还可以指定预期的
templateName
以及实际的template
内容:
App.PostsView = Ember.View.extend({
templateName: 'posts',
template: Ember.Handlebars.compile('I am the template')
});
这很奇怪。根据此页面:——“为template和templateName属性分配值将引发错误。”这描述了您看到的问题:
App.PostsView = Ember.View.extend({
templateName: 'posts',
template: Ember.Handlebars.compile('I am the template')
});