将Backbone.Marionette布局附加到"正文"

And*_*ich 4 backbone.js marionette

我有一个牵线木偶布局,我想直接附加到页面的元素.

App.Views.Layouts.Unauthenticated = Backbone.Marionette.Layout.extend
  template: "layouts/unauthenticated"
  regions:
   content: "#content"
   header: "#header"
   footer: "#footer"  
  views: {}

 initialize:->
  @el = $("body")
  @delegateEvents()
Run Code Online (Sandbox Code Playgroud)

然后在应用程序中,我这样做

App.layouts.unauthenticated = new App.Views.Layouts.Unauthenticated()
App.layouts.unauthenticated.render()
Run Code Online (Sandbox Code Playgroud)

布局未附加到页面.我如何将身体贴在身体上,而我已经将身体用作"el",因为我不需要额外的包装.

Der*_*ley 6

您需要el在视图的定义中设置,而不是在初始化程序中.


App.Views.Layouts.Unauthenticated = Backbone.Marionette.Layout.extend
  el: "body"
  template: "layouts/unauthenticated"
  regions: ...
Run Code Online (Sandbox Code Playgroud)