【问题标题】:Twitter TypeAhead.js Remote ExampleTwitter TypeAhead.js 远程示例
【发布时间】:2015-07-21 01:58:36
【问题描述】:

我正在尝试执行远程提前输入功能。我的远程 JSON 应该如何构建?在下面的示例中,用户对每个项目都有一个单独的 JSON 文件。我必须为我的数据创建这数千个文件吗?

https://github.com/twitter/typeahead.js/tree/gh-pages/data/films/queries

示例如下:

var bestPictures = new Bloodhound({
  datumTokenizer: Bloodhound.tokenizers.obj.whitespace('value'),
  queryTokenizer: Bloodhound.tokenizers.whitespace,
  prefetch: '../data/films/post_1960.json',
  remote: {
    url: '../data/films/queries/%QUERY.json',
    wildcard: '%QUERY'
  }
});

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

【问题讨论】:

    标签: typeahead.js


    【解决方案1】:

    您可以在后端动态创建 JSON 数据。 In PHP, e.g., you can use its json_encode function to achieve this.

    如果您对路线有困难,您可以更改它。以下两者的行为相同(给定正确的配置)–the second is actually typeaheads default

    ../data/films/queries/{query}.json
    ../data/films/queries?q={query}
    

    As for the JSON structure you should check out one of the examples you referenced.

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-12-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-10-26
      • 1970-01-01
      相关资源
      最近更新 更多