您需要创建链接到一个控制器中的新功能(作用)的路线让它命名为“ajaxGetSubCategoriesAction()”
实现它让所有的子类,那么这样的返回他们:
//get the category id from ajax request
$categoryID = $request->request->get('category_id');
//get all subcategories and return your result like this
return new Response(json_encode($result));
然后在呈现类别把数据字段的表单标签或类似
这个数据路径,你得到它的JS文件中div标签里面知道该功能的路径树枝您为ge创建t子类别。 $ posturl = $ formelement.data('path'); var categoryid = //从您的输入字段中获取它。 $就({ 类型: “POST”, URL:$ posturl, 异步:假, 数据类型: “JSON”, 数据:{ CATEGORY_ID:CATEGORYID }
}).done(function (response) {
inside response you will have all the subcategories returned from your ajaxGetSubCategories function
}
创建一个控制器将值列为'JSON',然后通过ajax加载值并使用'Form Transformer'使symfony接受附加值http://symfony.com/doc/current/cookbook/form/data_transformers.html – trrrrrrm 2014-09-05 08:27:01
也这可能有助于https://www.adayinthelifeof.nl/2014/03/19/dynamic-form-modification-in-symfony2/ – trrrrrrm 2014-09-05 08:28:38