我想在我的symfony2项目中使用typeahead.js。因此我有以下javascript:
$(document).ready(function(){
var players = new Bloodhound({
datumTokenizer: function(d) { return Bloodhound.tokenizers.whitespace(d.value); },
queryTokenizer: Bloodhound.tokenizers.whitespace,
remote: "{{ path('_api_player_search', {searchterm: '%QUERY', limit: 5}) }}",
prefetch: ''
});
players.initialize();
$('#searchfield').typeahead(null, {
displayKey: 'firstname',
source: players.ttAdapter(),
templates: {
suggestion: Handlebars.compile(
'{% verbatim %}<p><strong>{{firstname}}</strong> – {{lastname}}</p>{% endverbatim %}'
)
}
});
});
如您所见,我想将twig path
帮助程序创建的URL传递给remote:
配置的Bloodhound()
属性。 (后来我想为此目的使用FOSJsRoutingBundle。)
现在的问题是,Bloodhound()
不会替换我的twig表达式中的%QUERY
占位符。有没有办法实现这个目标?
非常感谢您的帮助! :)