我正在使用带有预编译模板的 Handlebars.js。我有以下代码(在第一行使用 JQuery):
$('#'+id).append('<script src="'+widgetContext.templateDir+
template+'.tmpl">');
console.log(Handlebars);
console.log(Handlebars.templates);
var html = Handlebars.templates[template](data);
我在控制台得到以下信息:
'widget_container' 模板文件肯定存在于指定的位置。我也尝试过标准的handelbars.js 和handelbars.runtime.js。
知道这里发生了什么或如何修复错误吗?
更新:如果 HTML 与 javascript 文件和模板在同一个域中,它似乎可以工作,但如果不是,那么它与相同的源策略有关吗?我在这里尝试使用车把 require.js 插件https://github.com/SlexAxton/require-handlebars-plugin但无法正常工作。