【问题标题】:typeahead.js does not trigger source functiontypeahead.js 不触发源函数
【发布时间】:2017-10-26 22:35:01
【问题描述】:

我正在尝试集成 twitter typeahead.js,为此我从https://github.com/twitter/typeahead.js 下载了库并包含typeahead.bundle.min.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"}
        ]);
    }
});

而且它有效。

【问题讨论】:

    标签: jquery twitter-bootstrap-3 typeahead twitter-typeahead


    【解决方案1】:

    试试这个, 您必须添加 bootstrap typeahead 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/

    【讨论】:

    • 你是对的,现在触发了,但是当我尝试返回JSON对象时,它没有显示,如何显示结果?
    • 我知道了,更新问题以供参考。谢谢。
    • 这里还有另一个“维护”的 typeahead.js 版本...github.com/corejavascript/typeahead.js
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-06
    • 2023-03-14
    • 1970-01-01
    • 2013-02-13
    • 1970-01-01
    相关资源
    最近更新 更多