Looking at the source of https://github.com/marionettejs/backbone.marionette/blob/master/src/marionette.collectionview.js we can see that:
getItemView: function(item){
var itemView = Marionette.getOption(this, "itemView");
if (!itemView){
throwError("An `itemView` must be specified", "NoItemViewError");
}
return itemView;
},
This means that it'll look for the itemView
attribute by default. However, if you override this function (as David Sulc is saying) you can do anything you want here. If you'd like, you can provide an object with views for example:
privObj.propertiesSubPanelView = Marionette.CollectionView.extend({
el: options.el,
itemViews: {
view1: itemView1,
view2: itemView2 // etc..
}
getItemView: function( item ) {
// Get the view key for this item
var viewId = item.get('viewId');
// Get all defined views for this CompositeView
var itemViewObject = Marionette.getOption(this, "itemViews");
// Get correct view using given key
var itemView = itemViewObject[viewId];
if (!itemView){
throwError("An `itemView` must be specified", "NoItemViewError");
}
return itemView;
}
});
// Create view instance
var viewInstance = new privObj.propertiesSubPanelView({
collection: col
});
// Your model might have the following attribute
model.get('viewId'); // returns 'view1';
There is also another error in your question, which is new Marionette.CollectionView({
. You can't do that, see the example above. You need to extend the view first before invoking the new
keyword on it.
Added a jsFiddle demonstrating the code above: http://jsfiddle.net/Cardiff/L8xG9/