【发布时间】:2015-08-17 09:11:32
【问题描述】:
在与 Twitter 的 typeahead.js 长期斗争之后,我终于可以决定应该使用哪个模板来提出建议了。
虽然这看起来是一个简单的过程,但我收到以下错误:
未捕获的类型错误:g.templates.suggestion 不是函数
我的代码是这样的
HTML:
<input id = "search" type="text" placeholder="Colors">
Javascript:
var colors = ["red", "blue", "green", "yellow", "brown", "black"];
var colorsource = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.whitespace,
queryTokenizer: Bloodhound.tokenizers.whitespace,
// `states` is an array of state names defined in "The Basics"
local: colors
});
$('#search').typeahead({
hint: true,
highlight: true,
minLength: 1
},
{
name: 'color',
source: colorsource,
templates: {
empty: [
'<div class="empty-message">',
'unable to find any Best Picture winners that match the current query',
'</div>'
].join('\n'),
suggestion: '<div>{{color}}</div>'
}
});
我已经看到使用 Handlebars.js 编译模板的示例,但我计划在我的建议中使用 Angular.js 中的变量,所以我不想这样做。
任何有关如何解决此问题的建议将不胜感激。
【问题讨论】:
标签: javascript jquery angularjs typeahead.js