CompositeView
ドロップダウンに入力するために使用しているマリオネットがあります。collection.fetch()
CompositeView 内から呼び出したときの JSON 応答はきれいですが、新しい ItemViewを追加する代わりに、CompositeViewが DOM でそれらを置き換えているようです。
これが私のコードです(coffeescript):
class @PDCollectionItemView extends Backbone.Marionette.ItemView
el: 'li'
template: Handlebars.compile('{{ title }}')
class @PDCollectionsView extends Backbone.Marionette.CompositeView
id: 'pd_collections'
className: 'selection'
itemView: PDCollectionItemView
itemViewContainer: '.scroll ul'
template: HandlebarsTemplates['connections/collection_select'] #handlebars_assets gem
ui:
modalTrigger: '#pd_collection_selector'
modal : '#pd_selection_modal'
selectBtn : '#select_collection'
initialize: ->
@selectedCollection = undefined
Connectors.App.vent.on "connections:collectionStaged", @assignSelectedCollection
return @PDCollectionsView
が呼び出される親レイアウトfetch
:
class @IndexLayout extends Backbone.Marionette.Layout
initialize: ->
@collections = new PDCollectionsCollection
@collectionsView = new PDCollectionsView
collection: @collections
onRender: ->
@collectionSelect.show @collectionsView
@collections.fetch
success: (collection, response, options) =>
Connectors.App.vent.trigger "connections:collectionsLoaded"
Connectors.App.vent.trigger "loadComplete"
error: (collection, response, options) =>
console.log response
appendHTML
呼び出しで項目を手動で追加しようとしましたが、同じ動作になります。itemView
を呼び出してそれぞれをonAfterItemAdded
ログに記録できます。@PDCollectionsView
項目ビューは個別です。さまざまなcid、および適切なモデル。