Backbone.Marionette CollectionView模板'undefined'

Nei*_*eil 2 collectionview backbone.js backbone-rails marionette

我一直在使用Brian Mann的BackboneRails截屏视频,所以我的应用程序结构完全符合这些.

以下定义了HomepageApp Marionette Appication的"show"部分.

My.module('HomepageApp.Show', function(Show, App, Backbone, Marionette, $, _){

  Show.Photo = Marionette.ItemView.extend({
    tagName:'span'
  });

  Show.Photos = Marionette.CollectionView.extend({  
    template: 'homepage/show/templates/photos',

    itemView:Show.Photo,
    itemViewContainer: '#photos'
  });

  Show.Layout = Marionette.Layout.extend({
    template: 'homepage/show/templates/layout',
    regions:{
      photoRegion: '#photo-region'
    }
  });
});
Run Code Online (Sandbox Code Playgroud)

我也用以下内容覆盖Marionette.Renderer.render函数:

Backbone.Marionette.Renderer.render = function(template, data){
  var path = JST["backbone/apps/" + template];  

  try{
    if(!path) throw({message: "Template '" + template + "' not found!"}); 
    return path(data);
  }

  catch(err){
    console.log(err.message);
  }
}
Run Code Online (Sandbox Code Playgroud)

我的所有观点,包括许多未在此处显示的观点都完美无缺.问题是Show.Photos CollectionView的'模板'属性在我的渲染器覆盖中变为'undefined',给出了以下错误:

Template 'undefined' not found!
Run Code Online (Sandbox Code Playgroud)

奇怪的是,当我根本没有为模板属性传递任何值时,甚至会发生这种情况.

我也知道我在实例化时传递了一个有效的Backbone集合.

我完全陷入了困境.有谁熟悉这种现象?

Ing*_*gro 11

CollectionView不应该有模板,为此你应该使用CompositeView,如文档中所述:

CompositeView从CollectionView扩展,用作复合视图,用于表示树结构中的分支和叶子的场景,或者需要在包装器模板中呈现集合的场景.

你可以在这里阅读更多内容:https://github.com/marionettejs/backbone.marionette/blob/master/docs/marionette.compositeview.md