github地址:https://github.com/twitter/typeahead.js

在aceAdmin界面模板中,有typeahead这一控件,版本号为0.10.2 , 这个版本对 minLength:0这个参数无效,所以我就到github中找到新版本0.11.1 替换,在此记录使用过程中的一些注意事项

基本代码

 var gameNameList = ['abc', 'abd', 'cde', 'xyz'];
var gameNameMatcher = function(strs) {
return function findMatches(q, cb) {
var matches, substrRegex; // an array that will be populated with substring matches
matches = []; // regex used to determine if a string contains the substring `q`
substrRegex = new RegExp(q, 'i'); // iterate through the pool of strings and for any string that
// contains the substring `q`, add it to the `matches` array
$.each(strs, function(i, str) {
if (substrRegex.test(str)) {
matches.push({value:str});
}
}); cb(matches);
};
};
$('#Name').typeahead({
hint: true,
highlight: true,
minLength: 0
}, {
name: 'gameNameList',
displayKey: 'value',
source: gameNameMatcher(gameNameList)
});

注意: 在github的example上,没有displayKey 这行,  matches.push里面的代码是 (str) 而不是({Value:str}) ,这样的结果就是在匹配的列表中只显示 undefined 。

minLength这个参数为0时,点击输入框则自动出列表,比较适合选项不多的情况。

配合aceAdmin使用时,会出现列表没有边框等显示效果异常,原因是版本升级后样式表不对,我采用修改ace.css来解决:

1 将 tt-dropdown-menu改为 tt-menu

2 增加一段css

.tt-suggestion:hover {
cursor: pointer;
color: #fff;
background-color: #0097cf;
}

最后,还要提一下版本问题,这个控件经过多次升级,最后从bootstrap里面独立出来了,所以在3.0以上版本中看不到这一控件。在网上大量的资料是基于早期版本的,与现有版本差异较大。

最新文章

  1. 关于war包 jar包 ear包 及打包方法
  2. Count Complete Tree Nodes
  3. c++容器(vector、list、deque)
  4. Codeforces Zepto Code Rush 2014 -C - Dungeons and Candies
  5. [Android Pro] AndroidStudio导出jar包
  6. Professional iOS Network Programming Connecting the Enterprise to the iPhone and iPad
  7. itoa 和_itoa_s
  8. 容器 list
  9. unity3D游戏开发十八之NGUI动画
  10. PropertyChangeSupport的使用
  11. JQuery+Ajax实现唯一性验证、正则
  12. django 用户管理相关的表
  13. 机器学习理论基础学习15---条件随机场(CRF)
  14. 峰Spring4学习(2)依赖注入的几种方式
  15. android 从零单排 第一期 按键显示helloworld
  16. Linux内核(1) - Kernel地图:Kconfig与Makefile
  17. 别名的使用注意,""真坑。
  18. 基于C#的UDP协议的同步实现
  19. CentOS6.5安装Cacti统计图乱码解决
  20. bzoj 1477 扩展欧几里德

热门文章

  1. C# 托管和非托管混合编程
  2. 合并两个java bean对象非空属性(泛型)
  3. MySQL中tinytext、text、mediumtext和longtext详解
  4. Use filter in outlook2013
  5. pycharm激活码,拿走不谢
  6. iOS-多线程 ,整理集锦,多种线程的创建
  7. .net 制作二维码
  8. SQLyog-直接导出JSON格式的数据
  9. 分拆素数和 HDU - 2098
  10. 正确理解ThreadLocal