jquery-Select2.min.js Uncaught TypeError:undefined不是函数+ rails4

时间:2014-07-11 03:12:08

标签: jquery ruby-on-rails-4

我在rails上使用了select2.min.js文件。以下错误抛弃了我。如何解决它。我花了很多时间来处理这个错误。我需要显示选择框

Select2.min.js Uncaught TypeError: undefined is not a function 
 ready                            unicorn.form_common.js?body=1:15
 (anonymous function)             jquery.turbolinks.js?body=1:30
 x.event.dispatch                 jquery.min.js?body=1:6
 v.handle                         jquery.min.js?body=1:6
 x.event.trigger                  jquery.min.js?body=1:6
 (anonymous function)             jquery.min.js?body=1:6 
 x.extend.each                    jquery.min.js?body=1:5
 x.fn.x.each                      jquery.min.js?body=1:5
 x.fn.extend.trigger              jquery.min.js?body=1:6
 $.turbo.onLoad                   jquery.turbolinks.js?body=1:36
 c                                jquery.min.js?body=1:5
 p.fireWith                       jquery.min.js?body=1:5
 x.extend.ready                   jquery.min.js?body=1:5
 q

我的unicorn.form_common.js及以下我提到错误行

  ready = function(){

    $('input[type=checkbox],input[type=radio]').iCheck({
        checkboxClass: 'icheckbox_flat-blue',
        radioClass: 'iradio_flat-blue'
    });

   $('select').select2();  **// this line error**
   $('.colorpicker').colorpicker();
   $('.datepicker').datepicker();
   }

   $(document).ready(ready);
   $(document).on('page:load', ready);

这是我的application.js

     // This is a manifest file that'll be compiled into application.js, which will       include all the files
     // listed below.
     //
     // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
     // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
    //
    // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
    // compiled file.
    //
    // Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
    // about supported directives.
    //
   // require jquery
  //= require jquery.min.js
  //= require jquery-ui.custom.js
  //= require jquery.turbolinks
  //= require jquery_ujs
  //= require bootstrap 
  //= require pusher.min.js
  //= require fullcalendar_engine/application
  //= require gritter
  //= require jquery_nested_form
  //= require activities
  //= require message.js
  //= require livevalidation.js
  //= require child_form_validation.js
  //= require signup_form_validation.js
  //= require custom_validation.js
  //= require timelineJS/embed
  //= require jquery.tokeninput
  //= require bootstrap-datepicker
  //= require newsletters
  //= require excanvas.min.js
  //= require bootstrap-colorpicker.js
  //= require jquery.flot.min.js
  //= require jquery.flot.resize.js
  //= require jquery.sparkline.min.js
  //= require fullcalendar.min.js
  //= require jquery.jpanelmenu.min.js
  //= require dropzone
  //= require unicorn.js
  //= require unicorn.dashboard.js
  //= require jquery.dataTables.min.js
  //= require unicorn.tables.js
  //= require filterrific-jquery
  //= require jquery.icheck.min.js
  //= require select2.min.js
  //= require unicorn.form_common.js
  //= require children
  //= require messagescroll.js.coffee
  //= require parents
  //= require custom.js
   // require unicorn.login.js
  //= require tution_fees.js
  //# require_tree . #should not use because of mercury editor

谢谢你的帮助!

3 个答案:

答案 0 :(得分:0)

在我的情况下,我有旧版本的jQuery没有" prop()"功能。

要找到您的问题,请使用未压缩的select2.js版本 寻找发生错误的地方。

答案 1 :(得分:0)

请确保在准备好功能

之前加载了jquery

答案 2 :(得分:-1)

您可以在application.js中删除require jquery.turbolinks。 它会工作。