0

我需要一些帮助。我对require.js 还很陌生,但遇到了障碍。我正在创建一个使用require.js架构的 jquery 插件。

一旦 setupSchedule 插件被调用,它就会传递调用它的元素的“this”变量。jQuery 101. 我的依赖ScheduleView需要这个“this”变量和设置变量。对于如何将这些变量提供给它,我想不出任何聪明的办法。

这样做的 require.js 方法是什么?

谢谢!!

define([
    'jquery',
    'underscore',
    'backbone',
    'libs/myFunctions/schedule/views/ScheduleView'
], function($, _, Backbone, ScheduleView){

    return $.fn.setupSchedule = function( options ) {

        // Settings
        var settings = $.extend({
            startTime   : 7,
            endTime     : 9,
            cellHeight  : 30,
            onsubmit    : function () {}
        }, options );

        var _this = this;

        new ScheduleView;

    }
});
4

1 回答 1

2

像下面这样启动。

new ScheduleView({element: this, settings: settings});

并在您的下面访问ScheduleView

 this.options.element //to get the element which called that plugin.
 this.options.settings //to get settings of that plugin.
于 2013-10-20T14:14:44.907 回答