2012-09-19 4 views
1

Backbone.Marionette을 시작하기 만하고 중첩 된 항목이 여러 개있는 구조를 렌더링하는 데 문제가 있습니다. 나는 많은 채널을 가지고있는 TV Guide를 가지고 있고 각 채널은 많은 프로그램을 가지고있다. json으로 구조는 다음과 같습니다Backbone.Marionette 및 중첩 된 구조의 렌더링

class App.Program extends Backbone.Model 

class App.Channel extends Backbone.Model 
    initialize: -> 
    @programs = new App.Programs(@attributes.programs) 

그리고 컬렉션 :

[ 
    { 
    "name":"HBO", 
    "number":"541", 
    "programs":[ 
     { 
     "name":"Game of Thrones" 
     }, 
     { 
     "name":"Gojir returns" 
     } 
    ] 
    }, 

    { 
    "name":"Showtime", 
    "number":"666", 
    "programs":[ 
     { 
     "name":"Alex Cook Saves Space" 
     }, 
     { 
     "name":"A Clockwork Orange" 
     } 
    ] 
    } 
] 

모델이 (사용하는 커피 스크립트)와 같은 설정이다

class App.Programs extends Backbone.Collection 
    model: App.Program 

class App.Channels extends Backbone.Collection 
    model: App.Channel 

class App.Guide extends Backbone.Collection 
    model: App.Channel 
    url: -> 'http://localhost:3000/guide' 

    initialize: -> 
    @on('reset', @setChannels) 

    setChannels: -> 
    @channels = new App.Channels(@models) 

다음과 같은 구조를 렌더링하는 관용적 인 방법이 될 것입니다 무엇 Backbone.Marionette 뷰를 사용하여 (내보기 구현 사촌을 빠져 나갔다.)

<table id="guide"> 
    <thead> 
    <tr> 
     <th>Channel</th> 
     <th>Program 1</th> 
     <th>Progarm 2</th> 
    </tr> 
    </thead> 
    <tbody> 
    <tr class="guide-row"> 
     <td class="channel">541:HBO</td> 
     <td class="program">Game of Thrones</td> 
     <td class="program">Gojira Returns</td> 
    </tr> 
    <tr class="guide-row"> 
     <td class="channel">666:Showtime</td> 
     <td class="program">Alex Cook Saves Space</td> 
     <td class="program">A Clockwork Orange</td> 
    </tr> 
    </tbody> 
</table> 

DOM에 렌더링 될 때 채널은 프로그램과 다른 이벤트 처리기를 가지므로 뚜렷하게 렌더링해야합니다.

도움이 될 것입니다.

답변

-1

당신은 모델에 대한 특정 템플릿 (전체 테이블) 및

1

좋아 행의에 대한 특정보기를 렌더링 Marionette's CompositeView을 사용할 수 있습니다, 우리는 해결책을 제공했다. 코드는 다음과 같습니다.

모델, 컬렉션 및보기의로드 순서가 문제였습니다. 이 견해는 매우 중요합니다. 우리는 itemView가 콜렉션/합성보기에 정의 /로드되지 않은 경우, 기본값은 부모 템플릿을 사용하여 itemView를 렌더링한다는 것을 발견했습니다.

관련 문제