typeerror:即使使用jQuery.noConflict,'undefined'也不是函数

Ani*_*nil 2 javascript jquery handlebars.js bootstrap-typeahead

我一直在为Handlebars.compile()调用获取TypeError.我尝试将jQuery.noConflict()添加到其他一些帖子中建议的各个地方,但没有运气.

TypeError: 'undefined' is not a function (evaluating 'Handlebars.compile('test')')
Run Code Online (Sandbox Code Playgroud)

代码是:

$('.location-typeahead').typeahead(
{
  name: 'states',
  displayKey: 'value',
  source: states(),
  templates: {
    header: '<h4 class="location-typeahead-header">Title</h4>',
    suggestion: Handlebars.compile('test')
  }
}
);
Run Code Online (Sandbox Code Playgroud)

如果我删除整个"suggestion"模板参数,我的JS工作正常.

mpe*_*pen 5

您可能已包含Handlebars的运行时版本.如果要在客户端编译模板,则需要包含完整版本.

或者,您可以预编译模板 - 然后您只需要运行时.