在最近的Ember.js Build中,在Ember.View中定义应用程序模板 [英] Define application template in Ember.View in the most recent Ember.js Build

查看:60
本文介绍了在最近的Ember.js Build中,在Ember.View中定义应用程序模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近升级到最新的Ember.js版本(从GitHub页面构建)。

I recently upgraded to the most recent Ember.js build (built from the GitHub page.)

使用新路由器时,这不再起作用吗? / p>

When using the new router, does this no longer work?

App.ApplicationView = Ember.View.extend({
    template: Ember.Handlebars.compile("Hello")
});

我更喜欢在我的js文件而不是index.html中定义我的模板。我相信它更清洁。但是,以上不会呈现!

I much prefer to define my templates in my js file rather than index.html. I believe it is much cleaner. However, the above does not render!

任何建议?谢谢!

推荐答案

对于Ember 1.0,应在 index.html 或通过构建工具提供给您的应用程序的单独文件。

For Ember 1.0, templates should be defined in index.html or in separate files that are provided to your application via a build tool.

一些示例:

  • For Grunt
  • For Brunch
  • For the Rails Asset Pipeline
  • For Iridium
  • A Standalone Precompiler

如果你真的想把你的模板放在JavaScript中,你可以把它放在你的应用程序模板中:

If you really, really want to put your template in JavaScript, you can put this in your application template:

<script type="text/x-handlebars">
  {{view App.MyView}}
</script>

然后定义您的视图:

App.MyView = Ember.View.extend({
  template: Ember.Handlebars.compile("Whatever you want here")
});

这就是说,Ember中的快乐路径是为每个路由使用外部模板,您的HTML开始时,或使用构建步骤,以便将其保留在您的index.html之外。

That said, the happy path in Ember is to use external templates for each of your routes, either in your HTML when you're getting started, or using a build step so you can keep them out of your index.html.

这篇关于在最近的Ember.js Build中,在Ember.View中定义应用程序模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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