gpt4 book ai didi

ember.js - 在最新的 Ember.js Build 中的 Ember.View 中定义应用程序模板

转载 作者:行者123 更新时间:2023-12-04 22:48:26 24 4
gpt4 key购买 nike

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

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

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

我更喜欢在我的 js 文件而不是 index.html 中定义我的模板。我相信它更干净。但是,上面没有渲染!

有什么建议?谢谢!

最佳答案

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

一些例子:

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

  • 如果你真的,真的想把你的模板放在 JavaScript 中,你可以把它放在你的应用程序模板中:
    <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 之外。

    关于ember.js - 在最新的 Ember.js Build 中的 Ember.View 中定义应用程序模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14271651/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com