jQuery   发布时间:2022-04-19  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了jquery – 前置自定义模板没有Handlebars大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我试图实现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引擎?

解决方法

使用此格式:
suggestion: function(data) {
    return '<p><strong>' + data.value + '</strong> – ' + data.year + '</p>';
}

取自this thread

大佬总结

以上是大佬教程为你收集整理的jquery – 前置自定义模板没有Handlebars全部内容,希望文章能够帮你解决jquery – 前置自定义模板没有Handlebars所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: