【发布时间】:2014-02-18 00:58:36
【问题描述】:
我不断收到 Handlebars.compile() 调用的 TypeError。我尝试按照其他帖子中的建议将 jQuery.noConflict() 添加到各个地方,但没有运气。
TypeError: 'undefined' is not a function (evaluating 'Handlebars.compile('test')')
代码是:
$('.location-typeahead').typeahead(
{
name: 'states',
displayKey: 'value',
source: states(),
templates: {
header: '<h4 class="location-typeahead-header">Title</h4>',
suggestion: Handlebars.compile('test')
}
}
);
如果我删除整个“建议”模板参数,我的 JS 工作正常。
【问题讨论】:
-
听起来不像是 jquery 问题。您是否在页面中包含了车把脚本?在开发者工具栏中输入
Handlebars会得到什么? -
> Handlebars < HandlebarsEnvironment COMPILER_REVISION: 4 Exception: function Exception(message, node) { HandlebarsEnvironment: function HandlebarsEnvironment(helpers, partials) { REVISION_CHANGES: Object SafeString: function SafeString(string) { Utils: Object VERSION: "1.3.0" VM: Object create: function () { createFrame: function (object) { helpers: Object log: function log(level, obj) { logger.log(level, obj); } logger: Object partials: Object template: function (spec) { __proto__: HandlebarsEnvironment -
您在该列表中看到
compile吗?我怀疑您包含了运行时版本,而不是完整版本。哦...或者错误可能在您的test模板中。 -
呃!我确实使用了运行时版本。下载其他版本后就可以使用了。谢谢!
-
犯了同样的错误。它发生了。我很高兴你也犯了错误,因为我找到了答案:-)
标签: javascript jquery handlebars.js bootstrap-typeahead