我需要一些帮助。 我对 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;
}
});
最佳答案
像下面一样启动。
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.
关于javascript - 使用 Backbone.js 和 require.js 的 jQuery 插件 - 如何将 "this"变量传递给依赖项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19478050/