Handlebars 例子提示 templateSpec.call is not a function
发布于 11 年前 作者 yakczh 9362 次预览 最后一次回复是 11 年前 来自
用 http://handlebarsjs.com 上的例子
var source=document.getElementById('entry-template').innerHTML;
var template = Handlebars.compile(source);
提示
TypeError: Handlebars.compile is not a function
然后用 Firebug 看了一个 没有 complie 方法, 有个 template 然后用 template 调用
var template = Handlebars.template(source);
返回是一个函数
template(data) 这样调用提示 templateSpec.call is not a function
3 回复
不可能没有compile方法吧。至于template方法,貌似不是你这样用的。
看下Handlebars.template的定义:
传入的参数是一个function,这也是为什么你调用Handlebars.template(source)之后会报 templateSpec.call is not a function 的错误。
按官网的例子写的