Typeahead.js 只提供前 5 个结果?

Typeahead.js deliver only first 5 results?

我只想在我的 json 文件中搜索字段 "value",但我只得到前 5 个结果。不管输入什么,每次都是一样的结果。

我的代码是:

$(function() {

      var search_url = 'https://twitter.github.io/typeahead.js/data/films/post_1960.json';
      var search_input = $("#prefetch input.typeahead");

      var search = new Bloodhound({
        datumTokenizer: Bloodhound.tokenizers.obj.whitespace('value'),
        queryTokenizer: Bloodhound.tokenizers.whitespace,
        prefetch: search_url,
        remote: {
          url: search_url + '?%QUERY.json',
          wildcard: '%QUERY'
        }
      });

      $('#prefetch .typeahead').typeahead(null, {
        name: 'search',
        display: 'value',
        displayKey: 'value',
        source: search.ttAdapter()
      });

    }); 

JSON结构:

[{
    "year": "1961",
    "value": "West Side Story",
    "tokens": [
      "West",
      "Side",
      "Story"
    ]
  },
  {
    "year": "1962",
    "value": "Lawrence of Arabia",
    "tokens": [
      "Lawrence",
      "of",
      "Arabia"
    ]
  },
  {
    "year": "1963",
    "value": "Tom Jones",
    "tokens": [
      "Tom",
      "Jones"
    ]
  }]

这里也是JSFiddle例子。

有可能让它工作吗?

您搜索的内容有误 url。来自 http://twitter.github.io/typeahead.js/examples/

remote: {
  url: '../data/films/queries/%QUERY.json',
  wildcard: '%QUERY'
}

改变

url: search_url + '?%QUERY.json',

url: 'https://twitter.github.io/typeahead.js/data/films/queries/%QUERY.json'