我有一個Backbone Marionette應用程序,下面定義了一個模塊。當我運行這個應用程序時,控制檯日誌語句打印出@
作爲窗口對象。當運行list
方法時,我認爲this
(@
)會引用List.Controller
對象。我錯過了什麼?爲什麼`this`引用全局對象?
###
The Header list controller.
###
define [
'cs!app',
'cs!./view',
'cs!modules/header/entities'
], (
App,
View
) ->
App.module 'Header.List', (List, App, Backbone, Marionette, $, _) ->
List.Controller =
list: ->
console.log(@)
headers = App.request 'header:entities'
view = new View.Headers {collection: headers}
App.headerRegion.show view
setActiveHeader: (headerUrl) ->
headers = App.request 'header:entities'
header = headers.find (header) -> (header.get 'url') == headerUrl
header.select()
headers.trigger 'reset'
App.commands.setHandler 'header:setActive', (headerUrl) ->
List.Controller.setActiveHeader headerUrl
App.Header.List.Controller
更新
這是調用列表法模塊:
###
The Header module.
###
define [
'cs!app',
'cs!./list/controller'
], (
App,
listController
) ->
App.module 'Header', (Module, App, Backbone, Marionette, $, _) ->
Module.startWithParent = false
App.module 'Routers.Header', (ModuleRouter, App, Backbone, Marionette, $, _) ->
class ModuleRouter.Router extends Marionette.AppRouter
appRoutes: {}
executeAction = (action, args) ->
action(args)
API =
list: ->
executeAction listController.list
App.Header.on 'start', ->
API.list()
App.addInitializer ->
new ModuleRouter.Router {listController: API}
App.Header
哪裏呼籲函數列表? – ekeren
我在我的更新中添加了呼叫。 – Erik