【问题标题】:Why won't my Ember template render?为什么我的 Ember 模板无法渲染?
【发布时间】:2013-03-18 07:50:21
【问题描述】:

Here's a fiddle for this question(在第 5 行添加/删除单斜杠并重新运行)

基本上,两种绑定(专有名词?)我的应用程序模板的方式。我希望这两种方法都能奏效,但一种有效,另一种无效。

作品

this.register( 'view:application',     Ember.View.extend());
this.register( 'template:application', Ember.Handlebars.compile( 'Hello, world!' ));

坏了

this.register( 'view:application', Ember.View.extend({
  'template': Ember.Handlebars.compile( 'Hello, world!' )
}));

这似乎适用于所有资源/路由,而不仅仅是应用程序级别。

那么,为什么第二种方法不起作用?

编辑:这是一个another fiddle,它显示了使用上述方法 2(已损坏)成功完成的 Handlebars 视图助手。看来这只是路线视图的问题。

编辑 2:感谢 c4p 这是 Github 上的一个问题

【问题讨论】:

    标签: javascript model-view-controller ember.js javascript-framework


    【解决方案1】:

    看看这个related question

    简短的总结:

    • Ember 期望在全局变量 Ember.TEMPLATES 中找到模板。当您使用 Ember.Handlebars.compile 时,编译后的模板会放入全局变量 Handlebars.templates
    • 如果你想用这种方式编译,你必须这样做:

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

    【讨论】:

    • 这里也讨论了这个问题:github.com/emberjs/ember.js/pull/2030
    • 如果你使用把手视图助手,你可以使用普通的template templateName -- jsfiddle.net/TSaF3/1
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-07-10
    • 2019-06-01
    • 2016-04-23
    • 1970-01-01
    • 2014-11-26
    • 1970-01-01
    相关资源
    最近更新 更多