我正在尝试在我的表单中使用 select2。
我安装了 GenemuFormBundle 并添加到内核中。然后我在 config.yml 中添加了几行
genemu_form:
select2: ~
date: ~
autocomplete: ~
然后我扩展奏鸣曲管理标准布局树枝
{% extends 'SonataAdminBundle::standard_layout.html.twig' %}
{% block javascripts %}
{{ parent() }}
<script src="{{ asset('bundles/admin/js/select2.js') }}" type="text/javascript"> </script>
{% if form is defined %}{{ form_javascript(form) }}{% endif %}
{% endblock %}
{% block stylesheets %}
{{ parent() }}
<script src="{{ asset('bundles/admin/css/select2.css') }}" type="text/css"></script>
{% if form is defined %}{{ form_stylesheet(form) }}{% endif %}
{% endblock %}
然后我在管理类中添加了一些代码
$formMapper
->with('General')
->add('category', 'genemu_jqueryselect2_entity', array('class' => 'AmanFrontendBundle:MtCat', 'property' => 'catName'))
做完这一切后,我得到了
AutoSuggest 不工作,为什么我得到一个文本框并下拉。
页面上加载的 javascript 和 css 是
<link rel="stylesheet" href="/aman/web/bundles/sonataadmin/bootstrap/css/bootstrap.min.css" type="text/css" media="all" />
<link rel="stylesheet" href="/aman/web/bundles/sonataadmin/bootstrap/css/bootstrap-responsive.min.css" type="text/css" media="all" />
<!-- base application asset -->
<link rel="stylesheet" href="/aman/web/bundles/sonataadmin/css/layout.css" type="text/css" media="all" />
<link rel="stylesheet" href="/aman/web/bundles/sonataadmin/css/colors.css" type="text/css" media="all" />
<script src="/aman/web/bundles/admin/css/select2.css" type="text/css"></script>
<script src="/aman/web/bundles/sonatajquery/jquery-1.8.3.js" type="text/javascript"></script>
<script src="/aman/web/bundles/sonatajquery/jquery-ui-1.8.23.js" type="text/javascript"></script>
<script src="/aman/web/bundles/sonatajquery/jquery-ui-i18n.js" type="text/javascript"></script>
<script src="/aman/web/bundles/sonataadmin/bootstrap/js/bootstrap.min.js" type="text/javascript"></script>
<script src="/aman/web/bundles/sonataadmin/jquery/jquery.form.js" type="text/javascript"></script>
<script src="/aman/web/bundles/sonataadmin/jquery/jquery.confirmExit.js" type="text/javascript"></script> <script src="/aman/web/bundles/sonataadmin/base.js" type="text/javascript"></script>
<script type="text/javascript">
jQuery(document).ready(function($) {
$field = $('#s5248479f910c0_category');
$field.select2({"placeholder":"Select a value","allowClear":false,"minimumInputLength":0,"width":"off"});
});
</script>
我也执行
sudo php app/console assets:install web/
还有什么我忘了补充。请帮帮我。