$('.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}]);
如何在此示例中编写JSON文件。 我从typeahead js examples
得到这个答案 0 :(得分:4)
如果您查看该网页的来源,则可以看到http://twitter.github.io/typeahead.js/js/examples.js上有附加的javascript文件
在这里,您可以查看它们如何绑定预先输入框:
$('.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
}
]);
您将看到可以访问预取JSON数据以查看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"
]
}
]