Ember.js RC1 - 指定“模板”时不显示视图 [英] Ember.js RC1 - view not displayed when specifying 'template'

查看:56
本文介绍了Ember.js RC1 - 指定“模板”时不显示视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  App.PostsView = Ember.View.extend({
模板:Ember.Handlebars.compile('我是模板')
});

但没有渲染。当我使用 templateName 时,视图 呈现:



// html

 < script type ='text / x-handlebars'data-template-name ='posts-template'> 
< h1>我是模板< / h1>
< / script>

// js

  App.PostsView = Ember.View.extend({
templateName:'posts-template'
});

如何使用模板来获取模板的工作功能,如指南中所述?



编辑:



确实遇到了这些:



emberjs模板编译在rc1中不起作用



如何在ember.js中指定使用带有编译的句柄的视图RC1



所以这个可能看起来像一个重复的。但是,这首先似乎使用了Ember指南中没有指定的一些额外的工作,第二个是我正在做的,但它不起作用。

解决方案

可以这样做:

  Ember.TEMPLATES ['posts-template'] = Ember.Handlebars.compile (我是模板); 
App.PostsView = Ember.View.extend({
templateName:'posts-template'
});

我们发生的是我们的预编译模板正在添加到 Handlebars.templates 而不是 Ember.TEMPLATES 以及我们使用此命令返回已编译的模板的事实,例如:

  App.PostsView = Ember.View.extend({
template:Handlebars.templates ['posts-模板']
});

所以似乎应该避免干扰模板函数,而是始终使用 templateName ,它将在 Ember.TEMPLATES



希望这可以帮助某人节省一些时间:)


Following the Ember guide on templates I do the following:

App.PostsView = Ember.View.extend({
    template: Ember.Handlebars.compile('I am the template')
});

But nothing is rendered. When I use the templateName the view is rendered:

// 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'
});

How can I get the templates to work using the template function as stated in the guides?

edit:

I did come across these:

emberjs template compile doesn't work in rc1

How do I specify using a view with a compiled handlebar in ember.js RC1

So this might look like a duplicate. However, this first appears to use some extra work not specified in the Ember guides and the second is what I am doing but it is not working.

解决方案

OK, this works:

Ember.TEMPLATES['posts-template'] = Ember.Handlebars.compile('I am the template');
App.PostsView = Ember.View.extend({
    templateName: 'posts-template'
});

What was happening in our was that our pre-compiled templates were being added to Handlebars.templates and not Ember.TEMPLATES along with the fact that we were returning the complied template using this, e.g.:

App.PostsView = Ember.View.extend({
    template: Handlebars.templates['posts-template']
});

So it seems as though one should refrain from interfering with the template function but rather always use the templateName which will be looking for that name in Ember.TEMPLATES.

Hopefully this helps someone save some time :)

这篇关于Ember.js RC1 - 指定“模板”时不显示视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆