Backbone.Marionette を使い始めたばかりで、複数のネストされたアイテムを含む構造のレンダリングに問題があります。多くのチャンネルを持つ TV ガイドがあり、各チャンネルには多くの番組があります。json 構造は次のとおりです。
[
{
"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"
}
]
}
]
モデルは次のようにセットアップされます (coffeescript を使用):
class App.Program extends Backbone.Model
class App.Channel extends Backbone.Model
initialize: ->
@programs = new App.Programs(@attributes.programs)
そしてコレクション:
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 にレンダリングすると、チャネルはプログラムとは異なるイベント ハンドラーを持つため、それらを明確にレンダリングする必要があります。
どんな助けでも大歓迎です!