【问题标题】:Typeahead UI ignoring options (v0.10)Typeahead UI 忽略选项 (v0.10)
【发布时间】:2014-02-27 09:25:35
【问题描述】:

我有一个 Typeahead 实例正在运行,从远程 URL 拉入 JSON,除了 UI 实例似乎忽略了我的几个选项,即“minLength”和“强调'。我使用的代码如下:

var airportsList = new Bloodhound({
    name: 'airports',
    limit: 20,
    remote: {url: "http://full-url-here/search/%QUERY",
           ajax: {type:'post',dataType:'jsonp',headers: {'cache-control': 'no-cache'}},
            filter: function (parsedResponse) { return parsedResponse.locations; }
  },
  datumTokenizer: function(d) { 
      return Bloodhound.tokenizers.whitespace(d.name); 
  },
  queryTokenizer: Bloodhound.tokenizers.whitespace
});

// initialize the bloodhound suggestion engine
airportsList.initialize();

// instantiate the typeahead UI
$('.typeaheadField').typeahead(null, {
    displayKey: 'name',
    minLength: 3,
    highlight: true,
    source: airportsList.ttAdapter()
});

查看我在 typeahead 实例中的参数,它肯定会获取 'displayKey' 和 'source' 的值,但由于某种原因似乎忽略了中间两个...?

【问题讨论】:

    标签: typeahead.js twitter-typeahead


    【解决方案1】:

    minLengthhighlight 是顶级配置,而不是每个数据集,所以试试这个:

    $('.typeaheadField').typeahead({
      minLength: 3,
      highlight: true
    }, 
    {
      displayKey: 'name',
      source: airportsList.ttAdapter()
    });
    

    【讨论】:

      猜你喜欢
      • 2015-09-24
      • 1970-01-01
      • 2021-04-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-05
      • 2016-03-10
      相关资源
      最近更新 更多