简体   繁体   English

如何在奏鸣曲管理捆绑Symfony2中实现onchange ajax请求

[英]how to implement onchange ajax request in sonata admin bundle Symfony2

I want to implement onchange ajax request in sonata admin bundle in Symfony2.I want to create a cascading dropdown.if i select option from a drop down then according to the value of the dropdown, the next dropdown will automatically populate the value. 我想在Symfony2的Sonata Admin包中实现onchange ajax请求。我想创建一个级联下拉列表。如果我从下拉列表中选择选项,然后根据下拉列表的值,下一个下拉列表将自动填充该值。

Any idea will be appreciated .. 任何想法将不胜感激..

I think you just have to override standard_layout.html.twig layout template and load your custom JS file. 我认为您只需要重写standard_layout.html.twig布局模板并加载自定义JS文件即可。

Note: Maybe you just have to override the CRUD edit template and not all the layout. 注意:也许您只需要覆盖CRUD编辑模板,而不是全部布局。 Create the file and specify it in your SonataAdminBundle configuration: 创建文件并在您的SonataAdminBundle配置中指定它:

sonata_admin:
    templates:
        edit: YourCustomBundle:CRUD:edit.html.twig

Then, override the javascript block to add your JS file: 然后,覆盖javascript块以添加您的JS文件:

{% block javascripts %}
    {{ parent() }}
    <script src="{{ asset('bundles/mycustombundle/myfile.js') }}" type="text/javascript"></script>
{% endblock %}

Finally, you just have to add a listener on your first dropdown field and make an AJAX request (when your selected value changed) that will point on a custom controller and return your second dropdown values. 最后,您只需要在第一个下拉字段中添加一个侦听器,并发出一个AJAX请求(更改所选值时),该请求将指向自定义控制器并返回第二个下拉值。

I think this should be ok. 我认为应该没问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM