我有一个Ajax路由,它会用一个从txt文件中获取它的站点来响应一个json数组。在我的树枝模板中,我使用typeahead函数执行ajax调用,例如:
var sites= new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.whitespace,
queryTokenizer: Bloodhound.tokenizers.whitespace,
remote: '{{'ajax_fun'}}'
});
$('#bloodhound .typeahead').typeahead({
name: 'sites',
source: sites
});
输入字段的筛选不起作用,即使我获得了带有位置的阵列也是如此。
如果有人想知道如何使用从远程路径获取的json数组填充状态,这是我的解决方案:
var states = [];
var statesBloodhound = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.whitespace,
queryTokenizer: Bloodhound.tokenizers.whitespace,
// `states` is an array of state names defined in "The Basics"
local: states
});
//populate the statesBloodhound
$.getJSON('path', {
}).done(function(data){
statesBloodhound.add(data);
})
$('#bloodhound .typeahead').typeahead({
name: 'statesBloodhound ',
source: statesBloodhound
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句