3

基本的に、コレクション内の各モデルが にレンダリングされ、. 私はDerick の例を少しだけ変更して非常に厳密にフォローしていますが、残念ながらかなり奇妙な結果が得られました。

各 itemView をレンダリングする代わりに、ビューはそれ自体を参照し、コレクション内の各アイテムを再レンダリングして、新しいテーブルとテーブル ヘッドを生成します。それ以前は、compositeView 自体をレンダリングしていました。

テンプレートがアイテムのグループであるitemViewと、それを参照するテーブルであるcompositeViewがあります

CompositeView:

class App.module('Views.Parts').Index extends Backbone.Marionette.CompositeView
   template: 'parts/index'
   itemView: App.Views.Parts.Part
   tagName: 'table'
   itemViewContainer: 'tbody'
   appendHtml: (collectionView, itemView, index)->
           collectionView.$el.append(itemView.el)

アイテムビュー:

class App.module('Views.Parts').Part extends Backbone.App.ItemView
       tagName: 'tr'
       template: 'parts/part'
       events:
               "click .destroy": "destroy"
       destroy: (e) ->
               e.preventDefault()
               @model.destroy()
       onRender: ->
               @stickIt()

コントローラー

class App.Controllers.Parts
       constructor: ->
               @parts = new App.Collections.Parts
               @parts.reset(App.parts)
               App.parts = null

       showView: (view)->
               App.mainRegion.show view

       index: ->
               view = new App.Views.Parts.Index
                       collection: @parts
               @showView view

CompositeView の前に ItemView を宣言する必要があるとも聞きましたが、これは Marionette Rails プロジェクトであるため、実際にはビューは別のディレクトリに存在します。それらの順序を宣言するか、別の方法でそれらを互いにバインドする必要がありますか?

4

2 に答える 2