javascript - marionette.js Controller 初始化中的 this.options 参数

标签 javascript controller marionette

嗯,我有一个 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 访问 ontwo 属性.one.

关于javascript - marionette.js Controller 初始化中的 this.options 参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20482612/

相关文章:

javascript - 如何允许脚本在单击链接以显示对话框后立即触发

javascript - Discord.js:检查机器人权限

javascript - 在 Backbone Marionette 中使用 iframe 主体作为区域

css - 使用 CSS 的正文背景颜色未反射(reflect)在 html 页面上

javascript - Marionette js 使用 requirejs 从 Controller 访问应用程序

javascript - 捏缩放后 iPhone 谷歌地图 v3 平移

javascript - 数字分组正则表达式

swift - 我无法将对象从 Storyboard连接到 Controller

angularjs - 根据状态更改按钮样式 angularjs

javascript - 在 2 个不同的 Controller AngularJS 中使用相同的功能