Mr.Tiffenbox
Mr.Tiffenbox

Reputation: 87

How would be the JSON is in this example?

$('.example-films .typeahead').typeahead([{name: 'best-picture-winners',
remote: '../data/films/queries/%QUERY.json',prefetch: '../data/films/post_1960.json',
template: '

{{value}} – {{year}}

',engine: Hogan}]);

how would be the JSON file written on this example. i get this from typeahead js examples

Upvotes: 0

Views: 1190

Answers (1)

nvuono
nvuono

Reputation: 3363

If you view the source of the page you can see that there is an attached javascript file at http://twitter.github.io/typeahead.js/js/examples.js

Here you can view how they bound the typeahead box:

 $('.example-films .typeahead').typeahead([
    {
      name: 'best-picture-winners',
      remote: '../data/films/queries/%QUERY.json',
      prefetch: '../data/films/post_1960.json',
      template: '<p><strong>{{value}}</strong> – {{year}}</p>',
      engine: Hogan
    }
  ]);

And you will see that you can access prefetch JSON data to see the formatting at http://twitter.github.io/typeahead.js/data/films/post_1960.json

[
  {
    "year": "1961",
    "value": "West Side Story",
    "tokens": [
      "West",
      "Side",
      "Story"
    ]
  },
  {
    "year": "1962",
    "value": "Lawrence of Arabia",
    "tokens": [
      "Lawrence",
      "of",
      "Arabia"
    ]
  },  {
    "year": "2012",
    "value": "Argo",
    "tokens": [
      "Argo"
    ]
  }
]

Upvotes: 4

Related Questions