Typeahead.js确实给了我建议,但没有选择它们 [英] Typeahead.js does give me suggestions but doesn't select them

查看:72
本文介绍了Typeahead.js确实给了我建议,但没有选择它们的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm using Bootstrap 3.0 and the latest version of Typeahead.js with the Hogan engine. I managed to get the remote loading of the suggestions to work (finally). Now the next hurdle is when a user clicks on a suggestion, how do I make that the word filled in the input? I thought this was probably done automatically but it doesn't for some reason? Is this just a basic line of JS I'm missing?

输入:

<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                                   
     });
});

我不得不提到的一件事,一切都在模态内.也许那会改变情况?提前致谢!

One thing I have to mention, everything is inside a modal. Maybe that changes the situation? Thanks in advance!

推荐答案

当typeahead不知道要填充哪些数据作为值时,会发生这种情况.确保JSON具有值"属性,或使用 valueKey

This happens when typeahead doesn't know what data you want to fill in as a value. Make sure that JSON has either "value" property, or change it with valueKey

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

这篇关于Typeahead.js确实给了我建议,但没有选择它们的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆