【发布时间】:2014-05-08 22:51:24
【问题描述】:
我有国家的 json 列表:http://vocab.nic.in/rest.php/country/json
我正在尝试使用 Bloodhound 建议引擎获取 country_id 和国家/地区名称。 O 尝试了以下代码:
var countries = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('country_name'),
queryTokenizer: Bloodhound.tokenizers.whitespace,
limit: 10,
prefetch: {
url: 'http://vocab.nic.in/rest.php/country/json',
filter: function(response) {
return response.countries;
}
}
});
$('#my-input').typeahead({
hint: true,
highlight: true,
minLength: 1
},
{
name: 'states',
displayKey: 'value',
source: countries.ttAdapter()
});
这不起作用。我应该如何更改代码以使其正常工作?
【问题讨论】:
-
vocab.nic.in/rest.php/country/json 是否与您的网站在同一个域中?如果没有,那么您需要使用“remote”而不是“prefetch”
标签: jquery json typeahead.js