嗯,我有一个 marionette.js Controller ,它有一个初始化函数(此代码是其他人传递给我的)。在这段代码中我发现初始化函数包含一个@options参数。它从何而来?有谁知道,例如,在路由器中,您是否可以以某种方式向 Controller 传递任何参数?顺便说一句,这是我的文件(我正在使用 require.js 和节点):
define (require, exports, module) ->
# framework dependencies
Marionette = require 'Backbone.Marionette'
# Actions
ShowLandingPageAction = require '../actions/show-landing-page-action'
class LandingPageController extends Marionette.Controller
initialize: (@options)->
@region = options.region
showLandingPage: ->
console.log '--showLandingPage--'
action = new ShowLandingPageAction
action.execute @region
@trigger 'set:active:home'
module.exports = LandingPageController
最佳答案
选项是创建 Controller 时传递给 Controller 的值:
var controller = new LandingPageController({
one: 1,
two: 2
});
传递的对象是您的选项,因此换句话说,您可以使用(例如)options 访问
.on
和 two
属性.one
关于javascript - marionette.js Controller 初始化中的 this.options 参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20482612/