Php Symfony-Twig-TypeAhead功能
我正在尝试实现typeAhead功能。我正在使用Symfony框架。但如果这似乎不起作用。 我得到的错误是 未捕获引用错误:未定义猎犬 我对symfony和twig很陌生。有人能告诉我为什么代码不起作用吗 小树枝Php Symfony-Twig-TypeAhead功能,php,symfony,twig,typeahead.js,Php,Symfony,Twig,Typeahead.js,我正在尝试实现typeAhead功能。我正在使用Symfony框架。但如果这似乎不起作用。 我得到的错误是 未捕获引用错误:未定义猎犬 我对symfony和twig很陌生。有人能告诉我为什么代码不起作用吗 小树枝 var国家=新猎犬({ datumTokenizer:Bloodhound.tokenizers.whitespace, queryTokenizer:猎犬,标记,空白, //url指向包含国家名称数组的json文件,请参阅 // https://github.com/twitt
var国家=新猎犬({
datumTokenizer:Bloodhound.tokenizers.whitespace,
queryTokenizer:猎犬,标记,空白,
//url指向包含国家名称数组的json文件,请参阅
// https://github.com/twitter/typeahead.js/blob/gh-pages/data/countries.json
预取:“{path('typeAhead')}”
});
//为'options'参数传入'null'将导致默认值
//正在使用的选项
$('#prefetch.typeahead').typeahead(null{
名称:'国家',
资料来源:国家
});
控制器(响应)
控制器(呈现细枝文件)
欢迎来到堆栈溢出 也许你指的是,你想要实现血腥(typeAhead的建议引擎)
如果是,请考虑添加<代码> Type Field.By.js,它既有Type和HuffID(您可以检查页面,也可以看到JQuery下面的链接):
感谢您的热烈欢迎。成功了!非常感谢你的帮助:)
/**
* @Route("/typeAhead", name="typeAhead")
*/
public function typeAheadAllAction(Request $request)
{
$products=$this->getDoctrine()->getRepository(products::class)->findAll();
$pr_name=array();
foreach($products as $product){
$name=$product->getName();
array_push($pr_name,$name);
}
return new Response(json_encode(array($pr_name)),100);
}
/**
* @Route("/test", name="test")
*/
public function testAction(Request $request)
{
return $this->render('typeahead.html.twig', array(
));
}
<script src="https://twitter.github.io/typeahead.js/releases/latest/typeahead.bundle.js"></script>