Ember.Handlebars.compile返回代码而不是把手输出

时间:2013-11-25 22:51:44

标签: ember.js handlebars.js

我的观点如下:

App.StarRatingView = Ember.View.extend({
    template: function() {
        return new Ember.Handlebars.compile('test')
    }
})

这应该在页面中插入test,而是插入compile()函数的定义:

function (context, options) { options = options || {}; var result = templateSpec.call(container, Handlebars, context, options.helpers, options.partials, options.data); var compilerInfo = container.compilerInfo || [], compilerRevision = compilerInfo[0] || 1, currentRevision = Handlebars.COMPILER_REVISION; if (compilerRevision !== currentRevision) { if (compilerRevision < currentRevision) { var runtimeVersions = Handlebars.REVISION_CHANGES[currentRevision], compilerVersions = Handlebars.REVISION_CHANGES[compilerRevision]; throw "Template was precompiled with an older version of Handlebars than the current runtime. "+ "Please update your precompiler to a newer version ("+runtimeVersions+") or downgrade your runtime to an older version ("+compilerVersions+")."; } else { // Use the embedded version info since the runtime doesn't know about this revision yet throw "Template was precompiled with a newer version of Handlebars than the current runtime. "+ "Please update your runtime to a newer version ("+compilerInfo[1]+")."; } } return result; }

为什么会发生这种情况?

2 个答案:

答案 0 :(得分:1)

它不期望一个功能。这应该可以解决问题

App.StarRatingView = Ember.View.extend({
    template: Ember.Handlebars.compile('test')
})

甚至更好:

App.StarRatingView = Ember.View.extend({
    templateName: 'test'
})

Ember现在将使用给定的模板名称渲染视图。

答案 1 :(得分:0)

您可以将template属性设置为已编译输出的内容:

App.StarRatingView = Ember.View.extend({
    template: Ember.Handlebars.compile('test')
})

http://emberjs.jsbin.com/uYOvUWU/1/edit

另请参阅使用templates in views

的emberjs文档