Я пытаюсь реализовать пример Typeahead.JS "Пользовательский шаблон" .
$('#custom-templates .typeahead').typeahead(null, {
name: 'best-pictures',
displayKey: 'value',
source: bestPictures.ttAdapter(),
templates: {
empty: [
'<div class="empty-message">',
'unable to find any Best Picture winners that match the current query',
'</div>'
].join('\n'),
suggestion: Handlebars.compile('<p><strong>{{value}}</strong> – {{year}}</p>')
}
});
В частности, эта строка:
suggestion: Handlebars.compile('<p><strong>{{value}}</strong> – {{year}}</p>')
Вначале я не понимал, что вам нужно явно требовать Handlebars в качестве зависимости:
Uncaught ReferenceError: Handlebars is not defined
Когда я удаляю Handlebars...
suggestion: '<p><strong>' + value + '</strong> – ' + year + '</p>'
Он дает другую ошибку JS:
Uncaught ReferenceError: value is not defined
Можно ли использовать настраиваемый шаблон представления без использования механизма Handlebars?