我有一個我用來填寫下拉列表的Marionette CompositeView
。當我從CompositeView中調用collection.fetch()
時,JSON響應是乾淨的,但是替代追加新的ItemViews,CompositeView似乎將替換爲它們在DOM中。Backbone Marionette:CompositeView替換項目而不是追加它們
這裏是我的代碼(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
呼叫嘗試手動附加項目,但我得到相同的行爲。我可以在@PDCollectionsView
上通過致電onAfterItemAdded
記錄每個itemView
,並且項目視圖是不同;不同的cids和適當的模型。
不幸的是,這並沒有解決這個問題。添加'remove:false'對渲染沒有影響,並且在提取完成後檢查集合顯示所有預期的模型都已添加。 –