Bootstrap 3 typeahead.js,使用与 Bootstrap 2 类似的功能 [英] Bootstrap 3 typeahead.js, use similar functions from Bootstrap 2

查看:31
本文介绍了Bootstrap 3 typeahead.js,使用与 Bootstrap 2 类似的功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经将Bootstrap 2更新到了Bootstrap 3,最大的问题是去掉了typeahead,推荐使用typeahead.js.所以我安装了它,并且 typeahead 的简单使用没有问题,但我也使用其他功能,例如:

I have updated Bootstrap 2 to Bootstrap 3, and the biggest problem is that typeahead has been removed, and it's recommended the use of typeahead.js. So I installed it, and the easy uses of typeahead work without problems, but I also use other functions like:

 $('#my_field').typeahead({
     source : [list_of_items],
     matcher: function(item) {
         foo();
         return item;
     },
     updater : function(item) {
         foo2();
         return item;
     },
     closed: function(item) {
       ...
     },
     autocompleted: function(item) {
       ...
     }
 });

如何使用 typeahead.js 实现类似的功能?

How can I implement similar functions using typeahead.js?

https://github.com/twitter/typeahead.js 下有一些函数,比如

Under https://github.com/twitter/typeahead.js are some functions like

typeahead:initialized, typeahead:opened, typeahead:closed

但是没有关于如何使用它们的示例

but there are no examples on how to use them

推荐答案

您也可以尝试使用旧"插件,请参阅:https://github.com/bassjobsen/Bootstrap-3-Typeahead.

You Could also try to use the "old" plugin, see: https://github.com/bassjobsen/Bootstrap-3-Typeahead.

typeahead:initialized 等你提到的是事件.您可以使用它们在事件发生时触发一些代码,例如 $('typeahead').on('typeahead:initialized',function()).

The typeahead:initialized etc your mention are events. You can use them to trigger some code when the event happens, like $('typeahead').on('typeahead:initialized',function()).

您可以使用 filter 函数添加匹配器等功能.

You could use the filter function to add functions like matcher.

当基准被渲染为建议时,基准对象是传递给模板引擎的上下文.这意味着如果您包含任何数据对象中的任意属性,这些属性将是可用于呈现建议的模板.

When datums are rendered as suggestions, the datum object is the context passed to the template engine. This means if you include any arbitrary properties in datum objects, those properties will be available to the template used to render suggestions.

这个可以用来实现高亮功能.

This can be use to implement the highlight function.

因此您必须区分数据函数、模板函数和事件.

So you will have to differentiate between data functions, template functions and events.

这篇关于Bootstrap 3 typeahead.js,使用与 Bootstrap 2 类似的功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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