首页 > 解决方案 > typeahead - minLength 触发建议列表

问题描述

我将 minLength 设置为 3 以在至少输入 3 个字符时触发建议列表。

但是当输入 1 个字符时下拉菜单打开。如何使这项工作?

$('#remote .typeahead').typeahead(null, {
  name: 'best-pictures',
  display: 'value',
  source: bestPictures,
  minLength: 3
});

小提琴: https ://jsfiddle.net/tomsx/bc6trhjk/

标签: javascripttypeahead.jsbloodhound

解决方案


根据这里的文档 - https://github.com/corejavascript/typeahead.js/blob/master/doc/jquery_typeahead.md#api,第一个参数是选项,不能为空。

将其更改为以下,它应该可以工作,

$('#remote .typeahead').typeahead({minLength: 3}, {
  name: 'best-pictures',
  display: 'value',
  source: bestPictures,
});

推荐阅读