[英]typeahead.js and API themoviedb
I would like to use the themoviedb API with typeahead (BootStrap framework), but i was blocked for using the API... 我想将themoviedb API与typeahead(BootStrap框架)一起使用,但由于使用该API而被阻止...
I have this code : 我有这个代码:
http://jsfiddle.net/koff75/uAXtd/ http://jsfiddle.net/koff75/uAXtd/
It will return in my console the JSON format, but i don't understand the typeahead integration... But, I follow this examples http://twitter.github.io/typeahead.js/examples/ whithout idea 它将在我的控制台中返回JSON格式,但我不了解typeahead集成...但是,我遵循以下示例http://twitter.github.io/typeahead.js/examples/没有任何想法
It seems to be like this ? 好像是这样吗?
$('.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
}
]);
Thanks for your help... :) 谢谢你的帮助... :)
The code you wrote was "blocked" as querying themoviedb API meant that your code would be making a cross domain request. 您编写的代码被“阻止”,因为查询moviedb API意味着您的代码将发出跨域请求。 These are blocked by default but you can get around this problem by making a JSONP request.
这些默认情况下被阻止,但是您可以通过发出JSONP请求来解决此问题。
I've created a working example of Typeahead.js which uses TheMovieDb API here: 我创建了一个使用TheMovieDb API的Typeahead.js的工作示例:
http://jsfiddle.net/Fresh/5ND8W/ http://jsfiddle.net/Fresh/5ND8W/
The code to implement the typeahead control is: 实现预输入控件的代码是:
$('#movies').typeahead({
displayKey: 'value',
header: '<b>Movie suggestions...</b>',
limit: 10,
minLength: 3,
remote: {
url : 'http://api.themoviedb.org/3/search/movie?query=%QUERY&api_key=470fd2ec8853e25d2f8d86f685d2270e',
filter: function (parsedResponse) {
retval = [];
for (var i = 0; i < parsedResponse.results.length; i++) {
retval.push({
value: parsedResponse.results[i].original_title,
tokens: [parsedResponse.results[i].original_title]
});
}
return retval;
},
dataType: 'jsonp'
}
});
Note that this answer is for Typeahead version 0.9.3. 请注意,此答案适用于Typeahead 0.9.3版。 A more up to date version for typeahead version 0.10.0, which makes use of a suggestion engine called Bloodhound, can be found here .
可在此处找到用于预定义版本0.10.0的最新版本,该版本使用了称为Bloodhound的建议引擎。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.