知道为什么@layout = @getLayoutView()
行会引发Uncaught TypeError: object is not a function
错误?我似乎无法弄明白。一如往常,任何帮助都非常感谢!
list_controller.js.coffee:
@Demo.module "UsersApp.List", (List, App, Backbone, Marionette, $, _) ->
List.Controller =
listUsers: ->
users = App.request "user:entities"
@layout = @getLayoutView()
App.mainRegion.show @layout
getLayoutView: ->
new List.Layout
list_view.js.coffee:
@Demo.module "UsersApp.List", (List, App, Backbone, Marionette, $, _) ->
List.Layout = new Marionette.LayoutView
template: "users/list/templates/list_layout"
编辑添加路由逻辑
user_app.js.coffee:
@Demo.module "UsersApp", (UsersApp, App, Backbone, Marionette, $, _) ->
class UsersApp.Router extends Marionette.AppRouter
appRoutes:
"users": "listUsers"
API =
listUsers: ->
UsersApp.List.Controller.listUsers()
App.addInitializer ->
new UsersApp.Router
controller: API
app.js.coffee:
@Demo = do (Backbone, Marionette) ->
App = new Marionette.Application
App.rootRoute = "users"
App.addRegions
headerRegion: "#header-region"
mainRegion: "#main-region"
footerRegion: "#footer-region"
App.addInitializer ->
App.module("HeaderApp").start()
App.module("FooterApp").start()
App.on "start", ->
if Backbone.history
Backbone.history.start()
@navigate(@rootRoute, trigger: true) if @getCurrentRoute() is ""
App
答案 0 :(得分:1)
我猜你应该从'Marionette.LayoutView'扩展List.Layout,但这里的代码片段创建了一个'Marionette.LayoutView'的实例。代码
List.Layout = new Marionette.LayoutView
template: "users/list/templates/list_layout"
应该是
class List.Layout extends Marionette.LayoutView
template: "users/list/templates/list_layout"