【问题标题】:Typeahead.js does give me suggestions but doesn't select themTypeahead.js 确实给了我建议,但没有选择它们
【发布时间】:2013-11-15 19:17:38
【问题描述】:

我正在使用 Bootstrap 3.0 和最新版本的 Typeahead.js 以及 Hogan 引擎。我设法让建议的远程加载工作(最终)。现在下一个障碍是当用户点击一个建议时,我如何让这个词填写在输入中?我认为这可能是自动完成的,但不是出于某种原因?这只是我缺少的基本 JS 行吗?

输入:

<input class="form-control typeahead playername-search">

这是JS:

$(document).ready(function() {
     $('.playername-search').typeahead({                               
          name: "playername-search",                
          remote: 'http://xxxx/%QUERY',
          template: '<p><strong>{{short_name}}</strong> – {{rating}}</p>',
          engine: Hogan                                   
     });
});

我不得不提一件事,一切都在模态中。也许这会改变情况?提前致谢!

【问题讨论】:

  • 这个插件应该可以开箱即用。选择建议时,您在控制台中看到了哪些错误?
  • 不,什么都没有。 :(
  • 我的建议甚至没有加载,任何想法,我尝试准备好文档

标签: javascript jquery twitter-bootstrap typeahead typeahead.js


【解决方案1】:

当 typeahead 不知道您要作为值填写的数据时,就会发生这种情况。确保 JSON 具有“值”属性,或使用 valueKey

进行更改
 $('.playername-search').typeahead({                               
      name: "playername-search",     
      valueKey: "short_name",           
      remote: 'http://xxxx/%QUERY',
      template: '<p><strong>{{short_name}}</strong> – {{rating}}</p>',
      engine: Hogan                                   
 });

【讨论】:

  • 谢谢!正是我想要的。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-12-24
  • 1970-01-01
  • 1970-01-01
  • 2023-03-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多