0
我想通过Ajax
-请求将Handlebars
模板按需交付到我的Ember.js
应用程序。我能够编译它的服务器上,我也能为String
提供类似以下的输出(function
):通过JSON按需提供预编译的把手模板
Ember.TEMPLATES["authentication"] = Ember.Handlebars.template(function anonymous(Handlebars,depth0,helpers,partials,data) {
this.compilerInfo = [2,'>= 1.0.0-rc.3'];
helpers = helpers || Ember.Handlebars.helpers; data = data || {};
var buffer = '', stack1, hashTypes, options, helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression;
data.buffer.push("<h1>Hooray! It works!</h1>\r\n");
hashTypes = {};
options = {hash:{},contexts:[depth0],types:["ID"],hashTypes:hashTypes,data:data};
data.buffer.push(escapeExpression(((stack1 = helpers.outlet),stack1 ? stack1.call(depth0, "main", options) : helperMissing.call(depth0, "outlet", "main", options))));
return buffer;
});
这正是String
我能够从得到收到JSON
对象。现在,我想这个预编译模板添加到Ember.TEMPLATES
对象是这样的:
if(typeof data.template === 'string' && data.template != '') {
var escapedTemplateString =
data.template.replace(/\\n/g, "\\n").replace(/\\r/g, "\\r").replace(/\\t/g, "\\t");
Ember.TEMPLATES[templateName] = Ember.Handlebars.template(new Function(escapedTemplateString));
}
但这种包装整个“字符串化”功能到另一个anonymous function(){}
和我没有得到任何模板。如果我用eval
解压'字符串化'功能,那么模板是undefined
...
有没有人知道如何得到一个function
没有任何从'字符串化'函数包装? 非常感谢您的时间提前;)