admin管理员组文章数量:1394743
I am using typeahead.js. I am using the prefetch options and need to parse the returned data. It's not throwing an error; it's not doing much of anything. I've looked for examples but none of them use the Prefetch Filter option.
Link to the prefetch documentation
My code (that does not work but throws no errors):
$('#autoplete').typeahead('destroy').typeahead( {
name: 'organizations',
prefetch: {
url: 'jsoncall',
filter: function() {
// Blatant hardcoded return value
return ['test-a','test-b','test'c];
}
}
}
);
My HTML:
<input id="autoplete" class="large-12" autoplete="off" type="text" placeholder="Enter school name">
My Confusion:
0________0
I am using typeahead.js. I am using the prefetch options and need to parse the returned data. It's not throwing an error; it's not doing much of anything. I've looked for examples but none of them use the Prefetch Filter option.
Link to the prefetch documentation
My code (that does not work but throws no errors):
$('#autoplete').typeahead('destroy').typeahead( {
name: 'organizations',
prefetch: {
url: 'jsoncall',
filter: function() {
// Blatant hardcoded return value
return ['test-a','test-b','test'c];
}
}
}
);
My HTML:
<input id="autoplete" class="large-12" autoplete="off" type="text" placeholder="Enter school name">
My Confusion:
0________0
Share
Improve this question
edited Jul 2, 2013 at 23:42
Meredith
4,4845 gold badges36 silver badges58 bronze badges
asked May 15, 2013 at 17:48
Jesse BurcsikJesse Burcsik
3673 silver badges13 bronze badges
1
- This has helped...stackoverflow./questions/16321544/… – Jesse Burcsik Commented May 15, 2013 at 22:45
1 Answer
Reset to default 6You can pass the returned data through the filter
function which then parses the data to your liking. So in your example above, you would do something like this:
$('#autoplete').typeahead({
name: 'organizations',
prefetch:
{
url: 'jsoncall',
filter: function(data){
// filter the returned data
return [data.movies[0].title, data.movies[1].title, data.movies[2].title];
}
}
}
);
The example above would work if your returned data set was a JSON object that looked something like this:
movies: [{id:12865, title:Kill Bill: Volume 1, year:2003, mpaa_rating:R, runtime:111,…},…]
0: {id:12865, title:Kill Bill: Volume 1, year:2003, mpaa_rating:R, runtime:111,…}
1: {id:12862, title:Kill Bill, Volume 2, year:2004, mpaa_rating:R, runtime:137,…}
2: {id:771237417, title:Kill Bill: The Whole Bloody Affair, year:2011, mpaa_rating:Unrated, runtime:,…}
3: {id:770998578, title:Angel of Death: Killer Nurse: A Bill Kurtis Special Report, year:2006,…}
4: {id:771352617, title:Kedi Billa Killadi Ranga, year:2013, mpaa_rating:Unrated, runtime:145,…}
total: 5
本文标签: javascriptUsing Prefetch Filter with typeaheadjs (Using basic options)Stack Overflow
版权声明:本文标题:javascript - Using Prefetch Filter with typeahead.js (Using basic options) - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744104170a2590989.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论