我正在准备使用 Backbone Marionette 迁移我的应用程序,但路由中出现错误:
window.App = new Backbone.Marionette.Application
Models: {}
Collections: {}
Views:
Layouts: {}
Routers: {}
layouts: {}
Helpers: {}
init: ->
App.start()
App.main.show(App.layouts.main)
App.addRegions
main: '#container'
App.addInitializer (options) ->
new App.Routers.Profiles()
Backbone.history.start()
$(document).ready ->
App.init()
这是我的路由器
class App.Routers.Profiles extends Backbone.Marionette.AppRouter
routes:
'profiles/:id': 'show'
show: (id) ->
@profile = new App.Models.Profile(id: id)
view = new App.Views.ProfilesShow(model: @profile)
@profiles = new App.Collections.Profiles(@profile)
@profile.fetch()
App.layout.content.show(view)
这是我的观点
class App.Views.ProfilesShow extends Backbone.Marionette.ItemView
template: JST['profiles/show']
initialize: ->
@model.on('change', @render, @)
render: ->
$(@el).html(@template(profile: @model))
@
这是我的主要布局
class App.Views.Layouts.Main extends Backbone.Marionette.Layout
template: JST['layouts/main']
regions:
content: '#content'
App.addInitializer ->
App.layouts.main = new App.Views.Layouts.Main()
当我尝试在 App.layout.content.show(view) 行中的布局中显示视图时,出现消息错误:“TypeError: App.layout is undefined”。我不知道我是否做得很好。