I've been messing around with typeahead.js templates.(我一直在搞乱typeahead.js模板。)
No matter what I do, I keep getting the following error:(无论我做什么,都会不断出现以下错误:)
Uncaught TypeError: this.displayText(...).toLowerCase is not a function in typeahead.min.js:2(未捕获的TypeError: this.displayText(...)。toLowerCase不是typeahead.min.js:2中的函数)
My JavaScript looks as following:(我的JavaScript如下所示:)
$('#search-field').typeahead({
display: 'value',
templates: {
suggestion: function(data) {
return '<p><strong>' + data.value + '</strong> – ' + data.titleid + '</p>';
}
},
source: function (query, process) {
return $.get(root + '/api/search.php', { query: query }, function (data) {
console.log('data:' + data); //outputs the JSON correctly.
data = $.parseJSON(data);
return process(data);
});
}
});
Where /api/search.php looks like:(/api/search.php如下所示:)
[{"value":"Name1","titleid":"Test1"},{"value":"Name2","titleid":"Test2"},{"value":"Name3","titleid":"Test3"}]
I've tried copying code from other examples directly into mine, sometimes even the whole piece, but that didn't solve it either, even though it did work in the example.(我曾尝试将其他示例中的代码直接复制到我的代码中,有时甚至复制到我的整个代码中,但这也没有解决它,即使它在示例中确实起作用。)
How can I solve this, and get the template to work?(如何解决此问题,并使模板正常工作?)
ask by Appel Flap translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…