js -建议不是一个函数
Typeahead.js - suggestion is not a function
在与twitter typeahead.js进行了长时间的斗争之后,我终于到了决定应该使用哪个模板来提供建议的时候了。
但是,尽管这看起来像一个简单的过程,我得到以下错误:Uncaught TypeError: g.t umplates .suggestion is not a function
我的代码是这样的
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中的变量,所以我不想这样做。
你的建议选项必须是一个返回HTML的函数,例如
...
suggestion: function(e) { return ('<div>' + e.value + '</div>'); }
...
我正在关注@potatopeelings,但是没有出现建议。
我的代码
$(document).ready(function () {
$("#penilai").typeahead({
source: function (query, process) {
var countries = [];
map = {};
return $.post('/Evaluation/JsonSenaraiPenilai', { query: query }, function (data) {
$.each(data, function (i, country) {
map[country.Evaluator_name] = country;
countries.push(country.Evaluator_name);
});
process(countries);
});
},
templates: {
empty: [
'<div class="empty-message">',
'unable to find any Best Picture winners that match the current query',
'</div>'
].join(''n'),
suggestion: function (e) { return ('<div>' + e.Evaluator_name + '-' + e.Evalator_staf_no + '</div>'); }
},
updater: function (item) {
var selectedShortCode = map[item].Evalator_staf_no;
$("#evalutor").val(selectedShortCode);
return item;
}
});
});
相关文章:
- 我可以在json对象中添加一个函数吗
- 如何在JQuery函数中定义一个值,然后调用另一个函数并使用该值
- 是否可以将一个函数输入连接到另一个函数调用的文本
- 在另一个函数中使用变量this
- 在另一个函数成功结束后调用该函数
- mongoose.connect undefined不是一个函数
- 监听器必须是一个函数
- 使用JS函数来使用另一个函数的语法?node.js
- 如何取消object.prototypes javascript的一个函数
- 从Chrome扩展名中的popup.html文件在background.js文件中运行一个函数
- 嵌套到另一个函数中的Fancybox函数;不起作用
- 如何在javascript中使用不止一个函数
- jQuery-在页面加载时执行一个函数
- jquery UI draggable:UI.children不是一个函数
- jQuery Mobile Undefined不是一个函数
- 如何在php中创建一个函数,该函数与文本区域一起工作,通过输入类似[color:red]的内容来打印具有等效颜色的文本
- javascript函数将数据添加到屏幕,但随后被另一个函数覆盖
- JS异常:animate不是一个函数
- 如何将一个函数附加到一个不存在的元素上
- JavaScript/jQuery-添加添加和删除类与下一个函数之间的延迟