jquery - JavaScript fullCalendar plugin reading 'applyAll' as undefined in gcal.js - Stack Overflow

I am attempting to use the google calendar module of the fullcalendar plugin in JavaScript. When I atte

I am attempting to use the google calendar module of the fullcalendar plugin in JavaScript. When I attempt to load the google calendar, the console is displaying:

Uncaught TypeError: Cannot read property 'applyAll' of undefined

The error is occurring on line 23 of gcal.js:

21| var fc = $.fullCalendar;
22| console.log($.fullCalendar);
23| var applyAll = fc.applyAll;

The console.log() that I have added returns $.fullCalendar as undefined, and then fc.applyAll is also returning undefined. My knowledge of JS is not good enough to fully understand what is going on in this file, and I am not sure what is going wrong.

Here is my html:

<head>
  <link rel='stylesheet' href='fullcalendar/fullcalendar.css' />
  <script src='fullcalendar/lib/jquery.min.js'></script>
  <script src='fullcalendar/gcal.js'></script>
  <script src='fullcalendar/lib/moment.min.js'></script>
  <script src='fullcalendar/fullcalendar.js'></script>
  <link href='style.css' rel='stylesheet' />
</head>
<body>
  <div id='calendar'></div>
</body>

My JavaScript:

    $(document).ready(function() {
      $('#calendar').fullCalendar({
        googleCalendarApiKey: 'my-api-key',
        events: {
          googleCalendarId: 'my-calendar-id'
        }
      });
    });

And I have downloaded the most recent version of gcal.js (there seemed to be a problem with the file, and the site provided a link to the most up to date version).

I am attempting to use the google calendar module of the fullcalendar plugin in JavaScript. When I attempt to load the google calendar, the console is displaying:

Uncaught TypeError: Cannot read property 'applyAll' of undefined

The error is occurring on line 23 of gcal.js:

21| var fc = $.fullCalendar;
22| console.log($.fullCalendar);
23| var applyAll = fc.applyAll;

The console.log() that I have added returns $.fullCalendar as undefined, and then fc.applyAll is also returning undefined. My knowledge of JS is not good enough to fully understand what is going on in this file, and I am not sure what is going wrong.

Here is my html:

<head>
  <link rel='stylesheet' href='fullcalendar/fullcalendar.css' />
  <script src='fullcalendar/lib/jquery.min.js'></script>
  <script src='fullcalendar/gcal.js'></script>
  <script src='fullcalendar/lib/moment.min.js'></script>
  <script src='fullcalendar/fullcalendar.js'></script>
  <link href='style.css' rel='stylesheet' />
</head>
<body>
  <div id='calendar'></div>
</body>

My JavaScript:

    $(document).ready(function() {
      $('#calendar').fullCalendar({
        googleCalendarApiKey: 'my-api-key',
        events: {
          googleCalendarId: 'my-calendar-id'
        }
      });
    });

And I have downloaded the most recent version of gcal.js (there seemed to be a problem with the file, and the site provided a link to the most up to date version).

Share Improve this question edited Jul 6, 2015 at 11:27 Ed Prince asked Jul 6, 2015 at 10:11 Ed PrinceEd Prince 7143 gold badges15 silver badges31 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 8

The problem is with the order you've imported the library files.

fullcalendar is a jQuery plugin, which usually means it will end up as a property on the jQuery object e.g. $.fullCalendar.

Now, the gcal file depends on that property being there, so that it can access the .applyAll method on it, however, you're loading gcal.js before you load fullcalendar.js.

If you change the ordering like this, it works without problems.

<script src='fullcalendar/lib/jquery.min.js'></script>
<script src='fullcalendar/lib/moment.min.js'></script>
<script src='fullcalendar/fullcalendar.js'></script>
<script src='fullcalendar/gcal.js'></script>

As a rule of thumb, try and put the files that you know have no dependencies (they don't rely on another library) first.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744604114a4583362.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信