我有一个木偶CompositeView
,我用它来填写下拉列表。当我collection.fetch()
从 CompositeView 中调用时,JSON 响应是干净的,但是CompositeView 似乎在 DOM中替换它们,而不是附加新的 ItemView。
这是我的代码(咖啡脚本):
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
,并且项目视图是不同的;不同的 cids 和适当的模型。