2016-12-04 67 views
0

我有一個ajax路由,它響應一個json數組,其中包含從txt文件獲取的網站。在我的樹枝模板即時通訊使用預輸入功能做一個Ajax調用,如:如何在symfony 3中使用twitter/tyepahead.js和blodhound來實現自動完成

var sites= new Bloodhound({ 
    datumTokenizer: Bloodhound.tokenizers.whitespace, 
    queryTokenizer: Bloodhound.tokenizers.whitespace, 

    remote: '{{'ajax_fun'}}' 
}); 


$('#bloodhound .typeahead').typeahead({ 
    name: 'sites', 
    source: sites 
}); 

輸入字段篩選甚至不工作我想獲得與網站的陣列。

回答

0

如果有人想知道如何填充狀態與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 
}); 
相關問題