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」というエラー メッセージが表示されます。良い練習をしているかどうかはわかりません。