I want to search in my json file only in field "value", but I get there only first 5 results. No matter what is typed, every time the same result.
My code is:
$(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 structure:
[{
"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"
]
}]
Here is also JSFiddle example.
Is possible to get it working?
You are searching with the wrong url. From http://twitter.github.io/typeahead.js/examples/
remote: {
url: '../data/films/queries/%QUERY.json',
wildcard: '%QUERY'
}
change
url: search_url + '?%QUERY.json',
to
url: 'https://twitter.github.io/typeahead.js/data/films/queries/%QUERY.json'
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.