2016-10-24 93 views
2

我正在使用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

你做完所有的捆綁包的安裝步驟? https://github.com/tetranz/select2entity-bundle#installation這聽起來像是沒有被正確注入的lib。也許確保你做了'assets:install'並清除了你的緩存。 – Chausser

+0

感謝您的回覆。 @Chausser是的我已經完成了所有安裝步驟,istalled資產,傾銷資產,清除緩存.. – Ld91

+0

安裝文件似乎建議您必須手動添加select2.js和select2.css到您的應用程序/ Resources/public/js和來自https://github.com/select2/select2/tree/4.0.0的css文件夾。你做到了嗎? – Chausser

回答

0

看來你可能會丟失一些相關性文件:

嘗試把https://github.com/select2/select2/blob/4.0.0/dist/css/select2.cssweb/css

,並把https://github.com/select2/select2/blob/4.0.0/dist/js/select2.jsweb/js

他們二人你assetic腳本添加:

'@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') }}" /> 

然後再次運行php app/console assets:install,看看是否能工程

+0

感謝您的回覆。當我傾銷文件與資產我有這個錯誤: [RuntimeException] 源文件「C:\ wamp64 \ www \ SBC \ app /../ web/js/select2.js」不存在。 – Ld91

+0

我多做了一些閱讀,看起來應該像這樣將靜態資產直接放到應用程序的Web文件夾中。我更新了答案以反映這一點。移動這些文件,然後再試一次 – Chausser

+0

Yess !!謝謝你,但你能向我解釋爲什麼不喜歡平時? – Ld91

相關問題