使用jQuery getScript方法访问加载的脚本

时间:2012-06-29 14:56:30

标签: jquery fullcalendar getscript

我正在使用$.getScript在我自己的插件中加载jQuery插件。问题是我只能访问加载的插件并在$.getScript方法的回调函数中实例化一个对象。

我想知道是否有办法在回调函数之外进行实例化。请参阅以下代码中的实际实现:

init = function( options ) {
    $.getScript('javascript/lib/fullcalendar-1.5.3/fullcalendar/fullcalendar.js', function() {
        // Instantiation is require to be done here
        self.fullCalendar(options);
    });

    self.opt = $.extend(true, {}, defaults, options);
    self.data('settings', self.opt);
    if (typeof options.test === 'function') {
        // I would liked to do this here but at this point fullcalendar is not defined
        self.fullcalendar(options);

        var tests = test.call(self, 3, 1);
        options.test.call(self, tests, null);
    }
}

1 个答案:

答案 0 :(得分:0)

创建一个全局变量,并在您启动fullCalendar时为其分配日历。

init = function( options ) {
    var myCalendar;

    $.getScript('javascript/lib/fullcalendar-1.5.3/fullcalendar/fullcalendar.js', function() {
                        // Instantiation is require to be done here
        myCalendar = self.fullCalendar(options);
    });

    // Test full Calendar
    var viewName = myCalendar.fullCalendar('getView').name;
    alert(viewName);
}

我没试过这个。但这只是一个主要想法。我希望这会有所帮助。

相关问题