我正在使用symfony2并尝试使用tetranz / select2entity-bundle。
我的layout.html.twig:
'@SBCPlatformBundle/Resources/public/jquery/dist/jquery.min.js'
'@SBCPlatformBundle/Resources/public/bootstrap/dist/js/bootstrap.min.js'
'@TetranzSelect2EntityBundle/Resources/public/js/select2entity.js'
和我的XXXType(表格):
->add('fournisseur', Select2EntityType::class, [
'multiple' => false,
'remote_route' => 'fournisseur_home',
'class' => 'SBCPlatformBundle:fournisseur',
'primary_key' => 'id',
'text_property' => 'name',
'minimum_input_length' => 2,
'page_limit' => 10,
'allow_clear' => true,
'delay' => 250,
'cache' => true,
'cache_timeout' => 60000, // if 'cache' is true
'language' => 'fr',
'placeholder' => 'Choisir ...',
])
所以我有这个错误:
main_select2entity_3.js:10 Uncaught TypeError: $s2.select2 is not a function
at HTMLSelectElement.<anonymous> (http://localhost/SBC/web/js/compiled/main_select2entity_3.js:10:13)
at Function.each (http://localhost/SBC/web/js/compiled/main_jquery.min_1.js:2:2861)
at n.fn.init.each (http://localhost/SBC/web/js/compiled/main_jquery.min_1.js:2:845)
at n.fn.init.$.fn.select2entity (http://localhost/SBC/web/js/compiled/main_select2entity_3.js:2:10)
at HTMLDocument.<anonymous> (http://localhost/SBC/web/js/compiled/main_select2entity_3.js:85:48)
at i (http://localhost/SBC/web/js/compiled/main_jquery.min_1.js:2:27151)
at Object.fireWith [as resolveWith] (http://localhost/SBC/web/js/compiled/main_jquery.min_1.js:2:27914)
at Function.ready (http://localhost/SBC/web/js/compiled/main_jquery.min_1.js:2:29707)
at HTMLDocument.J (http://localhost/SBC/web/js/compiled/main_jquery.min_1.js:2:29892)(anonymous function) @ main_select2entity_3.js:10each @ main_jquery.min_1.js:2each @ main_jquery.min_1.js:2$.fn.select2entity @ main_select2entity_3.js:2(anonymous function) @ main_select2entity_3.js:85i @ main_jquery.min_1.js:2fireWith @ main_jquery.min_1.js:2ready @ main_jquery.min_1.js:2J @ main_jquery.min_1.js:2
所以任何人都可以帮忙解决这个问题吗?
答案 0 :(得分:1)
您似乎可能遗漏了一些依赖项文件:
尝试将server {
server_name app;
root /var/www/app/web;
# Redirect to blog
location ~* ^/blog {
proxy_set_header Accept-Encoding "";
sub_filter 'https://testproject.wordpress.com/' '/blog/';
sub_filter_once off;
rewrite ^/blog/(.*) /$1 break;
rewrite ^/blog / break;
proxy_pass https://testproject.wordpress.com;
}
# Serve index.html only for exact root URL
location / {
try_files $uri /app_dev.php$is_args$args;
}
location ~ ^/(app|app_dev|config)\.php(/|$) {
fastcgi_pass php-upstream;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param HTTPS off;
# Prevents URIs that include the front controller. This will 404:
# http://domain.tld/app_dev.php/some-path
# Remove the internal directive to allow URIs like this
internal;
}
location ~* ^.+\.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|pdf|txt|tar|wav|bmp|rtf|js|flv|swf|xml|html|htm)$ {
# clear all access_log directives for the current level
access_log off;
add_header Cache-Control no-cache;
# set the Expires header to 31 December 2037 23:59:59 GMT, and the Cache-Control max-age to 10 years
expires 1s;
}
error_log /var/log/nginx/app_error.log;
access_log /var/log/nginx/app_access.log;
}
放入https://github.com/select2/select2/blob/4.0.0/dist/css/select2.css
将web/css
放入https://github.com/select2/select2/blob/4.0.0/dist/js/select2.js
然后将它们添加到资产脚本中:
web/js
如果需要,请在模板中包含样式:
'@SBCPlatformBundle/Resources/public/jquery/dist/jquery.min.js'
'@SBCPlatformBundle/Resources/public/bootstrap/dist/js/bootstrap.min.js'
'js/select2.js'
'@TetranzSelect2EntityBundle/Resources/public/js/select2entity.js'
然后再次运行<link rel="stylesheet" href="{{ asset('css/select2.css') }}" />
并查看是否有效