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

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

问题描述

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

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

使用新路由器时,这是否不再有效?

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.

一些例子:

如果你真的、真的想把你的模板放在 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天全站免登陆