【发布时间】:2015-05-27 05:25:39
【问题描述】:
我正在尝试实现 Typeahead.JS "Custom Template" example。
$('#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 引擎的情况下使用自定义视图模板?
【问题讨论】:
标签: jquery typeahead.js