typeahead.js不会触发源的功能

问题描述:

我试图整合Twitter的typeahead.js,为了这个,我从https://github.com/twitter/typeahead.js下载库,其中包括typeahead.bundle.min.jstypeahead.js不会触发源的功能

我加入以下

<input type="text" class="form-control typeahead font-normal"> 
$('.typeahead').typeahead({ 
    source: function(query, process) { 
     console.log(query); 
    } 
}); 

问题它是否触发源函数,我期待它在控制台中打印查询。它没有。

这里可能有什么问题?

谢谢。

以下解决方案工作。

如答案指出,添加以下库第一

  1. jquery.min.js
  2. typeahead.bundle.min.js(https://twitter.github.io/typeahead.js/
  3. typeahead.jquery。 min.js(https://twitter.github.io/typeahead.js/
  4. bootstrap3-typeahead.min.js(https://github.com/bassjobsen/Bootstrap-3-Typeahead

然后初始化下面的代码

$('.typeahead').typeahead({ 
    source: function(query, process) { 
     process([ 
      {id: "1", name: "Display name 1"}, 
      {id: "2", name: "Display name 2"} 
     ]); 
    } 
}); 

和它的作品。

试试这个, 您必须添加引导预输入JS

<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-3-typeahead/4.0.2/bootstrap3-typeahead.js"></script> 

的jsfiddle为同一 https://jsfiddle.net/aa7zyyof/17/

+0

你是对的,这个现在被触发,但是当我尝试返回JSON对象,它不显示,如何显示结果? –

+0

我明白了,更新问题以供参考。谢谢。 –

+1

还有另一个typeahead.js的“维护”版本... https://github.com/corejavascript/typeahead.js – Artistan