我正在做一个http://www.backbonerails.com/教程,它有点过时了。我正在尝试渲染一个headers.jst.eco模板,它显示" BackBoneRails Demo"作为标题并从getLinksCollection(下面的代码)中的list_controller.js.coffee链接中的Backbone.Collection中呈现链接。相反,它会多次渲染标题模板,不会加载链接/名称,并在屏幕截图中如下所示
这是源代码
应用程序/资产/ Javascript角/骨干/应用/报头/列表/模板/ _header.jst.eco
<a href="#"><%= @name %></a>
应用程序/资产/ Javascript角/骨干/应用/报头/列表/模板/ headers.jst.eco
<nav class="navbar navbar-default" id="header">
<div class="container">
<div class="pull-left">
<span class="navbar-brand">BackboneRails Demo</span>
</div>
<ul class="nav navbar-nav pull-right">
</ul>
</div>
应用程序/资产/ Javascript角/骨干/应用/报头/列表/ list_view.js.coffee
@Demo.module "HeaderApp.List", (List, App, Backbone, Marionette, $, _) ->
class List.Header extends Marionette.ItemView
template: "header/list/templates/_header"
tagName: "li"
class List.Headers extends Marionette.CompositeView
template: "header/list/templates/headers"
itemView: List.Header
itemViewContainer: "ul"
</nav>
应用程序/资产/ Javascript角/骨干/应用/报头/列表/ list_controller.js.coffee
@Demo.module "HeaderApp.List", (List, App, Backbone, Marionette, $, _) ->
List.Controller =
listHeader: ->
links = @getLinksCollection()
headerView = @getHeaderView links
App.headerRegion.show headerView
getLinksCollection: ->
new Backbone.Collection [
{ name: "Link 1"}
{ name: "Link 2"}
{ name: "Link 3"}
]
getHeaderView: (links) ->
new List.Headers
collection: links
应用程序/资产/ Javascript角/骨干/应用/报头/ header_app.js.coffee
@Demo.module "HeaderApp", (HeaderApp, App, Backbone, Marionette, $, _) ->
@startWithParent = false
API =
listHeader: ->
HeaderApp.List.Controller.listHeader()
HeaderApp.on "start", ->
API.listHeader()
应用程序/资产/ Javascript角/骨干/ app.js.coffee
@Demo = do (Backbone, Marionette) ->
App = new Marionette.Application
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()
App
(Didn不包含FooterApp代码,因为它工作且与标题模板无关)
答案 0 :(得分:1)
Marionette有一些微妙的变化。 itemView
和ìtemViewContainer
现在称为childView
和childViewContainer
:
List.Headers = App.Views.CompositeView.extend({
template: 'header/list/templates/headers',
childView: List.Header,
childViewContainer: 'ul'
});
(抱歉肮脏的JavaScript,但我比CoffeScript更习惯;)