我试图在rails 6中使用gem select2-rails中的select2。
我已经添加了gemfile gem "select2-rails",运行了bundle和yarn add select2,以及.js require("select2")上的inport,但是当我尝试使用时,我得到了这个错误。
$(...).select2 is not a function我是怎么搞定这个的?
发布于 2020-05-27 05:44:21
下面是在Rails 6中设置select2的步骤:
jquery和select2:纱线添加jquery select2
阿拉巴马州。怀俄明州
从'jquery‘导入'select2’导入‘select2 2/dist/css/select2.css’window.addEventListener('DOMContentLoaded',() => {$(‘..select2’).select2() })
compile: true in config/webpacker.yml。运行webpack-dev-server是可选的。有关更多信息,您还可以查看这个演示:https://github.com/rossta/rails6-webpacker-demo/compare/example/select2
https://stackoverflow.com/questions/62033851
复制相似问题