【发布时间】:2013-08-19 05:14:57
【问题描述】:
我有一个手动预编译并保存为的车把模板 - testTemplate.handlebars。
现在,在我的 requireJS + Backbone 代码中,我有以下函数 -
define(['text!../templates/testTemplate.handlebars'
],function(testTemplate){
var myView = Backbone.View.extend(
initialize: function(options){
this.template = Handlebars.template(testTemplate);
},
render: function(data){
$(this.el).html(this.template(data));
}
);
});
所以 testTemplate.handlebars 以字符串形式返回 Javascript 代码,当传递给 Handlebars.template 时返回 JS 函数。当我尝试在控制台上打印我在 this.template 变量中得到的值时,它会显示 -
function (n,r){return r=r||{},e.call(t,Handlebars,n,r.helpers,r.partials,r.data)}
但是,当 render 函数的 $(this.el).html(this.template(data)); 行执行时,它会给出一条错误消息 - Uncaught Typeerror : object has no method call。 (尽管我可以看到一个 e.call 函数)
我在这里做错了吗?
另外,当我尝试编译模板运行时,渲染函数可以工作。 在运行时编译 Handlebars.compile(testTemplate) 时返回以下函数 -
function (e,t){return n||(n=r()),n.call(this,e,t)}
【问题讨论】:
标签: javascript backbone.js requirejs handlebars.js precompiled-templates