I have a problem: My CollectionViewdoes not display mine ItemViews. I pass the collection from layout to collection view. I collect the collection in CollectionView:
In the layout:
this.articles = new Articles(null, {
organizationId : this.model.organizationId,
projectId : this.model.id
});
var articlesView = new ArticleCollectionView({ collection : this.articles});
this.articlesRegion.show(articlesView);
In CollectionView:
define([
'marionette',
'templates',
'i18n!nls/projectDashboard',
'views/projectDashboard/ArticleItem'
], function (Marionette, templates, msg, ArticleItemView) {
return Marionette.CollectionView.extend({
initialize : function () {
this.listenTo(this.collection, "reset", this.render);
this.collection.fetch();
},
itemView : ArticleItemView
});
});
In ItemView:
define([
'marionette',
'templates',
'models/Article'
],
function (Marionette, templates, Article) {
return Marionette.ItemView.extend({
initialize : function () {
console.log('itemviewrender');
},
template : templates.projectDashboard.articleItem
});
});
Setup generally works. I found one way to make this work: select a collection in the layout and show CollectionViewin the region in the success callback.
But adding Collection listeners to the collection fails. For the present and declarative listeners, no event is raised, for example
this.collection.on('reset', this.render, this);
or
collectionEvents : {
'reset' : 'render'
}
I just want to reload the View with it item Views collection if the collection is received. I'm sure I missed something. Any help is appreciated!
: - :
, CollectionView , . : , . , this.collection.fetch() initialize . . - , .