2013-03-13 29 views
2

我一直在關注Brian Mann的BackboneRails screencast,所以我的應用程序結構與這些完全一致。Backbone.Marionette CollectionView模板'undefined'

以下定義了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' 
    } 
    }); 
}); 

我也重寫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); 
    } 
} 

我所有的意見,其中包括許多這裏沒有顯示完美地工作。問題是,Show.Photos的CollectionView的「模板」屬性爲轉彎在我的渲染器倍率爲「未定義」給我下面的錯誤:

Template 'undefined' not found! 

奇怪的是,這甚至發生在我傳球沒有值的模板屬性。

我也知道我正在通過它實例化一個有效的Backbone集合。

我完全卡住了。任何人都熟悉這種現象?

回答

11

一個的CollectionView是不應該有一個模板,爲了這個目的,你應該使用CompositeView中,如在文檔中指出:

A CompositeView extends from CollectionView to be used as a composite view for scenarios where it should represent both a branch and leaf in a tree structure, or for scenarios where a collection needs to be rendered within a wrapper template.

你可以在這裏閱讀更多:https://github.com/marionettejs/backbone.marionette/blob/master/docs/marionette.compositeview.md

+0

你救了我的命; ) –

相關問題