我正在使用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
因此,任何一個可以幫助解決這個問題?
你做完所有的捆綁包的安裝步驟? https://github.com/tetranz/select2entity-bundle#installation這聽起來像是沒有被正確注入的lib。也許確保你做了'assets:install'並清除了你的緩存。 – Chausser
感謝您的回覆。 @Chausser是的我已經完成了所有安裝步驟,istalled資產,傾銷資產,清除緩存.. – Ld91
安裝文件似乎建議您必須手動添加select2.js和select2.css到您的應用程序/ Resources/public/js和來自https://github.com/select2/select2/tree/4.0.0的css文件夾。你做到了嗎? – Chausser